4141from .. import redis
4242from ..checks import has_redis_json , has_redisearch
4343from ..connections import get_redis_connection
44- from ..util import ASYNC_MODE
44+ from ..util import ASYNC_MODE , has_numeric_inner_type , is_numeric_type
4545from .encoders import jsonable_encoder
4646from .render_tree import render_tree
4747from .token_escaper import TokenEscaper
@@ -406,7 +406,6 @@ class RediSearchFieldTypes(Enum):
406406
407407
408408# TODO: How to handle Geo fields?
409- NUMERIC_TYPES = (float , int , decimal .Decimal )
410409DEFAULT_PAGE_SIZE = 1000
411410
412411
@@ -578,7 +577,7 @@ def resolve_field_type(field: "FieldInfo", op: Operators) -> RediSearchFieldType
578577 )
579578 elif field_type is bool :
580579 return RediSearchFieldTypes .TAG
581- elif any ( issubclass ( field_type , t ) for t in NUMERIC_TYPES ):
580+ elif is_numeric_type ( field_type ):
582581 # Index numeric Python types as NUMERIC fields, so we can support
583582 # range queries.
584583 return RediSearchFieldTypes .NUMERIC
@@ -1805,7 +1804,7 @@ def schema_for_type(cls, name, typ: Any, field_info: PydanticFieldInfo):
18051804 schema = cls .schema_for_type (name , embedded_cls , field_info )
18061805 elif typ is bool :
18071806 schema = f"{ name } TAG"
1808- elif any ( issubclass ( typ , t ) for t in NUMERIC_TYPES ):
1807+ elif is_numeric_type ( typ ):
18091808 vector_options : Optional [VectorFieldOptions ] = getattr (
18101809 field_info , "vector_options" , None
18111810 )
@@ -2004,9 +2003,7 @@ def schema_for_type(
20042003 field_info , "vector_options" , None
20052004 )
20062005 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 )
20102007 except IndexError :
20112008 raise RedisModelError (
20122009 f"Vector field '{ name } ' must be annotated as a container type"
@@ -2104,7 +2101,11 @@ def schema_for_type(
21042101 # a proper type, we can pull the type information from the origin of the first argument.
21052102 if not isinstance (typ , type ):
21062103 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+ )
21082109
21092110 # TODO: GEO field
21102111 if is_vector and vector_options :
@@ -2127,7 +2128,7 @@ def schema_for_type(
21272128 schema += " CASESENSITIVE"
21282129 elif typ is bool :
21292130 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 ):
21312132 schema = f"{ path } AS { index_field_name } NUMERIC"
21322133 elif issubclass (typ , str ):
21332134 if full_text_search is True :
0 commit comments