Skip to content

Commit

Permalink
Fix TypeError: issubclass() arg 1 must be a class in nested model lis…
Browse files Browse the repository at this point in the history
…t code
  • Loading branch information
Tinitto committed Dec 12, 2022
1 parent 1598d9c commit ac8a42b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pydantic_redis/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,12 @@ def __eager_load_nested_model_lists(
[{"___books": ["id1", "id2"]}] becomes [{"books": [Book{"id": "id1", ...}, Book{"id": "id2", ...}]}]
"""
field = strip_leading(prefixed_field, IN_LIST_NESTED_MODEL_PREFIX)
model_type = field_types.get(field).__args__[0]
# in case the field is Optional e.g. books: Optional[List[Model]]
if not issubclass(model_type, Model):
field_type = field_types.get(field)
model_type = field_type.__args__[0]

# in case the field is Optional e.g. books: Optional[List[Model]], an alias for Union[List[Model], None]
is_optional = field_type.__origin__ == Union
if is_optional:
model_type = model_type.__args__[0]

for record in data:
Expand Down

0 comments on commit ac8a42b

Please sign in to comment.