Closed hozn closed 2 years ago
Hi there.
This seems to be a bug with how we determine if a given value is a Union
type and the 3.10 union syntax. The error is here:
repr(model_field.outer_type_).split("[")[0] == "typing.Union"
, where I would assume that either pydantic changed its logic respective of union typings, or that python itself has a different repr for these types.
I will have time to check this during the weekend, unless you or someone else would like to give it a go.
It seems that the repr method is different for the 3.10 union syntax.
uuid.UUID | str | None
so I guess the is_union function in utils.py could be changed into something like this.
def is_union(model_field: ModelField) -> bool:
"""Determines whether the given model_field is type Union"""
if repr(model_field.outer_type_).split("[")[0] == "typing.Union":
return True
elif "|" in repr(model_field.outer_type_):
return True
else:
False
If you add a PR with some test cases for this it would be great.
Will add PR today.
v1.2.7 released, thanks to @DaanRademaker for the PR! please confirm this issue is resolved and if it is - close this issue @hozn
Thank you both! I will test this out.
Confirmed fixed; thanks again.
When I have
__allow_none_optionals__= True
I'm getting an error:
RecursionError: maximum recursion depth exceeded while getting the repr of an object
Here's a simple (python 3.10) reproduce script:
Version info: