|
41 | 41 | from .. import redis
|
42 | 42 | from ..checks import has_redis_json, has_redisearch
|
43 | 43 | from ..connections import get_redis_connection
|
44 |
| -from ..util import ASYNC_MODE |
| 44 | +from ..util import ASYNC_MODE, has_numeric_inner_type, is_numeric_type |
45 | 45 | from .encoders import jsonable_encoder
|
46 | 46 | from .render_tree import render_tree
|
47 | 47 | from .token_escaper import TokenEscaper
|
@@ -406,7 +406,6 @@ class RediSearchFieldTypes(Enum):
|
406 | 406 |
|
407 | 407 |
|
408 | 408 | # TODO: How to handle Geo fields?
|
409 |
| -NUMERIC_TYPES = (float, int, decimal.Decimal) |
410 | 409 | DEFAULT_PAGE_SIZE = 1000
|
411 | 410 |
|
412 | 411 |
|
@@ -578,7 +577,7 @@ def resolve_field_type(field: "FieldInfo", op: Operators) -> RediSearchFieldType
|
578 | 577 | )
|
579 | 578 | elif field_type is bool:
|
580 | 579 | return RediSearchFieldTypes.TAG
|
581 |
| - elif any(issubclass(field_type, t) for t in NUMERIC_TYPES): |
| 580 | + elif is_numeric_type(field_type): |
582 | 581 | # Index numeric Python types as NUMERIC fields, so we can support
|
583 | 582 | # range queries.
|
584 | 583 | return RediSearchFieldTypes.NUMERIC
|
@@ -1375,14 +1374,6 @@ def outer_type_or_annotation(field: FieldInfo):
|
1375 | 1374 | return field.annotation.__args__[0] # type: ignore
|
1376 | 1375 |
|
1377 | 1376 |
|
1378 |
| -def _is_numeric_type(type_: Type[Any]) -> bool: |
1379 |
| - args = get_args(type_) |
1380 |
| - try: |
1381 |
| - return any(issubclass(args[0], t) for t in NUMERIC_TYPES) |
1382 |
| - except TypeError: |
1383 |
| - return False |
1384 |
| - |
1385 |
| - |
1386 | 1377 | def should_index_field(field_info: Union[FieldInfo, PydanticFieldInfo]) -> bool:
|
1387 | 1378 | # for vector, full text search, and sortable fields, we always have to index
|
1388 | 1379 | # We could require the user to set index=True, but that would be a breaking change
|
@@ -1813,7 +1804,7 @@ def schema_for_type(cls, name, typ: Any, field_info: PydanticFieldInfo):
|
1813 | 1804 | schema = cls.schema_for_type(name, embedded_cls, field_info)
|
1814 | 1805 | elif typ is bool:
|
1815 | 1806 | schema = f"{name} TAG"
|
1816 |
| - elif any(issubclass(typ, t) for t in NUMERIC_TYPES): |
| 1807 | + elif is_numeric_type(typ): |
1817 | 1808 | vector_options: Optional[VectorFieldOptions] = getattr(
|
1818 | 1809 | field_info, "vector_options", None
|
1819 | 1810 | )
|
@@ -2012,7 +2003,7 @@ def schema_for_type(
|
2012 | 2003 | field_info, "vector_options", None
|
2013 | 2004 | )
|
2014 | 2005 | try:
|
2015 |
| - is_vector = vector_options and _is_numeric_type(typ) |
| 2006 | + is_vector = vector_options and has_numeric_inner_type(typ) |
2016 | 2007 | except IndexError:
|
2017 | 2008 | raise RedisModelError(
|
2018 | 2009 | f"Vector field '{name}' must be annotated as a container type"
|
@@ -2137,7 +2128,7 @@ def schema_for_type(
|
2137 | 2128 | schema += " CASESENSITIVE"
|
2138 | 2129 | elif typ is bool:
|
2139 | 2130 | schema = f"{path} AS {index_field_name} TAG"
|
2140 |
| - elif any(issubclass(typ, t) for t in NUMERIC_TYPES): |
| 2131 | + elif is_numeric_type(typ): |
2141 | 2132 | schema = f"{path} AS {index_field_name} NUMERIC"
|
2142 | 2133 | elif issubclass(typ, str):
|
2143 | 2134 | if full_text_search is True:
|
|
0 commit comments