@@ -107,6 +107,7 @@ def embedded(cls):
107107
108108
109109def is_supported_container_type (typ : Optional [type ]) -> bool :
110+ # TODO: Wait, why don't we support indexing sets?
110111 if typ == list or typ == tuple :
111112 return True
112113 unwrapped = get_origin (typ )
@@ -479,8 +480,7 @@ def expand_tag_value(value):
479480 if isinstance (value , str ):
480481 return escaper .escape (value )
481482 if isinstance (value , bytes ):
482- # TODO: We don't decode and then escape bytes objects passed as input.
483- # Should we?
483+ # TODO: We don't decode bytes objects passed as input. Should we?
484484 # TODO: TAG indexes fail on JSON arrays of numbers -- only strings
485485 # are allowed -- what happens if we save an array of bytes?
486486 return value
@@ -966,15 +966,14 @@ class PrimaryKey:
966966 field : ModelField
967967
968968
969- class BaseMeta (abc . ABC ):
969+ class BaseMeta (Protocol ):
970970 global_key_prefix : str
971971 model_key_prefix : str
972972 primary_key_pattern : str
973973 database : aioredis .Redis
974974 primary_key : PrimaryKey
975975 primary_key_creator_cls : Type [PrimaryKeyCreator ]
976976 index_name : str
977- abstract : bool
978977 embedded : bool
979978 encoding : str
980979
@@ -994,7 +993,6 @@ class DefaultMeta:
994993 primary_key : Optional [PrimaryKey ] = None
995994 primary_key_creator_cls : Optional [Type [PrimaryKeyCreator ]] = None
996995 index_name : Optional [str ] = None
997- abstract : Optional [bool ] = False
998996 embedded : Optional [bool ] = False
999997 encoding : str = "utf-8"
1000998
@@ -1269,17 +1267,23 @@ def __init_subclass__(cls, **kwargs):
12691267 super ().__init_subclass__ (** kwargs )
12701268
12711269 for name , field in cls .__fields__ .items ():
1270+ origin = get_origin (field .outer_type_ )
1271+ if origin :
1272+ for typ in (Set , Mapping , List ):
1273+ if issubclass (origin , typ ):
1274+ raise RedisModelError (
1275+ f"HashModels cannot index set, list,"
1276+ f" or mapping fields. Field: { name } "
1277+ )
1278+
12721279 if issubclass (field .outer_type_ , RedisModel ):
12731280 raise RedisModelError (
1274- f"HashModels cannot have embedded model " f"fields. Field: { name } "
1281+ f"HashModels cannot index embedded model fields. Field: { name } "
1282+ )
1283+ elif dataclasses .is_dataclass (field .outer_type_ ):
1284+ raise RedisModelError (
1285+ f"HashModels cannot index dataclass fields. Field: { name } "
12751286 )
1276-
1277- for typ in (Set , Mapping , List ):
1278- if issubclass (field .outer_type_ , typ ):
1279- raise RedisModelError (
1280- f"HashModels cannot have set, list,"
1281- f" or mapping fields. Field: { name } "
1282- )
12831287
12841288 async def save (self , pipeline : Optional [Pipeline ] = None ) -> "HashModel" :
12851289 self .check ()
@@ -1360,6 +1364,8 @@ def schema_for_fields(cls):
13601364 for name , field in cls .__fields__ .items ():
13611365 # TODO: Merge this code with schema_for_type()?
13621366 _type = field .outer_type_
1367+ is_subscripted_type = get_origin (_type )
1368+
13631369 if getattr (field .field_info , "primary_key" , None ):
13641370 if issubclass (_type , str ):
13651371 redisearch_field = (
@@ -1372,7 +1378,12 @@ def schema_for_fields(cls):
13721378 schema_parts .append (redisearch_field )
13731379 elif getattr (field .field_info , "index" , None ) is True :
13741380 schema_parts .append (cls .schema_for_type (name , _type , field .field_info ))
1375- elif is_supported_container_type (_type ):
1381+ elif is_subscripted_type :
1382+ # Ignore subscripted types (usually containers!) that we don't
1383+ # support, for the purposes of indexing.
1384+ if not is_supported_container_type (_type ):
1385+ continue
1386+
13761387 embedded_cls = get_args (_type )
13771388 if not embedded_cls :
13781389 # TODO: Test if this can really happen.
0 commit comments