Skip to content

Commit ac8a42b

Browse files
committed
Fix TypeError: issubclass() arg 1 must be a class in nested model list code
1 parent 1598d9c commit ac8a42b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pydantic_redis/model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,12 @@ def __eager_load_nested_model_lists(
184184
[{"___books": ["id1", "id2"]}] becomes [{"books": [Book{"id": "id1", ...}, Book{"id": "id2", ...}]}]
185185
"""
186186
field = strip_leading(prefixed_field, IN_LIST_NESTED_MODEL_PREFIX)
187-
model_type = field_types.get(field).__args__[0]
188-
# in case the field is Optional e.g. books: Optional[List[Model]]
189-
if not issubclass(model_type, Model):
187+
field_type = field_types.get(field)
188+
model_type = field_type.__args__[0]
189+
190+
# in case the field is Optional e.g. books: Optional[List[Model]], an alias for Union[List[Model], None]
191+
is_optional = field_type.__origin__ == Union
192+
if is_optional:
190193
model_type = model_type.__args__[0]
191194

192195
for record in data:

0 commit comments

Comments
 (0)