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
@@ -1805,7 +1804,7 @@ def schema_for_type(cls, name, typ: Any, field_info: PydanticFieldInfo):
1805
1804
schema = cls .schema_for_type (name , embedded_cls , field_info )
1806
1805
elif typ is bool :
1807
1806
schema = f"{ name } TAG"
1808
- elif any ( issubclass ( typ , t ) for t in NUMERIC_TYPES ):
1807
+ elif is_numeric_type ( typ ):
1809
1808
vector_options : Optional [VectorFieldOptions ] = getattr (
1810
1809
field_info , "vector_options" , None
1811
1810
)
@@ -2004,9 +2003,7 @@ def schema_for_type(
2004
2003
field_info , "vector_options" , None
2005
2004
)
2006
2005
try :
2007
- is_vector = vector_options and any (
2008
- issubclass (get_args (typ )[0 ], t ) for t in NUMERIC_TYPES
2009
- )
2006
+ is_vector = vector_options and has_numeric_inner_type (typ )
2010
2007
except IndexError :
2011
2008
raise RedisModelError (
2012
2009
f"Vector field '{ name } ' must be annotated as a container type"
@@ -2104,7 +2101,11 @@ def schema_for_type(
2104
2101
# a proper type, we can pull the type information from the origin of the first argument.
2105
2102
if not isinstance (typ , type ):
2106
2103
type_args = typing_get_args (field_info .annotation )
2107
- typ = type_args [0 ].__origin__
2104
+ typ = (
2105
+ getattr (type_args [0 ], "__origin__" , type_args [0 ])
2106
+ if type_args
2107
+ else typ
2108
+ )
2108
2109
2109
2110
# TODO: GEO field
2110
2111
if is_vector and vector_options :
@@ -2127,7 +2128,7 @@ def schema_for_type(
2127
2128
schema += " CASESENSITIVE"
2128
2129
elif typ is bool :
2129
2130
schema = f"{ path } AS { index_field_name } TAG"
2130
- elif any ( issubclass ( typ , t ) for t in NUMERIC_TYPES ):
2131
+ elif is_numeric_type ( typ ):
2131
2132
schema = f"{ path } AS { index_field_name } NUMERIC"
2132
2133
elif issubclass (typ , str ):
2133
2134
if full_text_search is True :
0 commit comments