You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also tried with 1.7.3 with Python 3.8 and the bug still happens.
After reading https://pydantic-docs.helpmanual.io/usage/dataclasses/ I understand why dataclasses in a model get replaced with a different type which behaves (almost) the same as the original dataclass.
Unfortunately comparison between instances of the original dataclass (defined with order=True) and the derived pydantic one doesn't work.
fromdataclassesimportdataclassimportpydantic@dataclass(order=True)classDC:
num: int=42classModel(pydantic.BaseModel):
dc: DCreal_dc=DC()
model=Model(dc=real_dc)
print(f"Real dataclass: {real_dc}; model's dataclass: {model.dc}")
# This works as expected.assertreal_dc<=real_dcassertmodel.dc<=model.dctry:
# This raises a TypeError.assertreal_dc<=model.dcexceptTypeErrorasexc:
print(f"Comparison failed: {exc}")
The output is:
Real dataclass: DC(num=42); model's dataclass: DC(num=42)
Comparison failed: '<=' not supported between instances of 'DC' and 'DC'
Sorry I didn't mean it's the exact same issue but it's clearly related.
Now builtin dataclasses are converted into pydantic dataclasses when used in a model.
This is great and all but it breaks the __eq__, __gt__ and stuff that expect the exact same class.
I think it's worth keeping this issue open to think of all cases and not only __eq__
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:I also tried with 1.7.3 with Python 3.8 and the bug still happens.
After reading https://pydantic-docs.helpmanual.io/usage/dataclasses/ I understand why dataclasses in a model get replaced with a different type which behaves (almost) the same as the original dataclass.
Unfortunately comparison between instances of the original dataclass (defined with
order=True
) and the derived pydantic one doesn't work.The output is:
I thought this would help:
But the result is the same. I guess that
arbitrary_types_allowed
only applies to types not handled by pydantic at all, is that correct?The text was updated successfully, but these errors were encountered: