-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken loading list of tuples. #1190
Comments
I suspect this is because internally from pydantic import BaseModel
class OperationData(BaseModel):
id: str
class Operation(BaseModel):
__root__: Tuple[int, OperationData]
class ParseAsObjectModel(BaseModel):
__root__: Operation which then fails, should be fixable via either or both:
It occurs to me that 1. might not be possible (or possible without complex or backwards incompatible changes) due to the way we handle custom root types. The second option therefore might be easier. |
For what it's worth, the following change seems to make the error go away: to else:
if cls.__custom_root_type__:
value_as_dict = {"__root__": value}
else:
try:
value_as_dict = dict(value)
except (TypeError, ValueError) as e:
raise DictError() from e
return cls(**value_as_dict) I don't necessarily think this is the optimal fix, but it might be useful as a starting point. |
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:There is pretty strange behaviour on loading nested list of tuples. I firstly think that this might be intended, but then found out that parse_obj and parse_obj_as give different execution flow which frustrates me.
It doesn't look like a right behaviour.
The text was updated successfully, but these errors were encountered: