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 have searched GitHub for a duplicate issue and I'm sure this is something new
I have searched Google & StackOverflow for a solution and couldn't find anything
I have read and followed the docs and still think this is a bug
I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)
Description
Since v1.10.*, it seems that pydantic does not find anymore certain attributes even though they are available in the classes. Moreover, it seems that pydantic.dataclasses.dataclass has some side effects on the provided objects now.
Consider the following MWE where we set up a dummy dataclass
fromdataclassesimportdataclassasvanilla_dataclassfromdataclassesimportfield, make_dataclassfromtypingimportClassVarfrompydantic.dataclassesimportdataclassclassFoo():
bar: str='cat'default_config=make_dataclass(
cls_name=Foo.__name__,
bases=(vanilla_dataclass(Foo),),
fields=[("bar", ClassVar[str], field(default=Foo.bar))]
)
Then, we pass this dataclass to pydantic and subsequently ask for the bar attribute:
In pydantic<=1.9.2, this code runs successfully and will first print cat and then dog.
However since v1.10.* the second last line (setattr(config, "bar", "dog")) will raise:
Initial Checks
Description
Since
v1.10.*
, it seems that pydantic does not find anymore certain attributes even though they are available in the classes. Moreover, it seems thatpydantic.dataclasses.dataclass
has some side effects on the provided objects now.Consider the following MWE where we set up a dummy dataclass
Then, we pass this dataclass to pydantic and subsequently ask for the
bar
attribute:In
pydantic<=1.9.2
, this code runs successfully and will first printcat
and thendog
.However since
v1.10.*
the second last line (setattr(config, "bar", "dog")
) will raise:This is surprising because the attribute is actually there! The third last line will find the attribute and print its value ("cat").
Even more suprisingly, it seems that this issue can be fixed upon calling
dataclass
twice.will run through.
This seems to suggest that
dataclass
has some side effects on the passed object (default_config
).It would be great to hear your thoughts on this.
Example Code
No response
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: