pydantic.dataclasses.dataclass
does not inherit dataclasses.Field
to the new dataclass object.
#4353
Closed
5 of 16 tasks
Labels
Initial Checks
Description
pydantic.dataclasses.dataclass
does not inheritdataclasses.Field
to the new dataclass.The function
pydantic.dataclasses._process_class
. claims to create dynamically a new dataclass with the exact same fields as the base dataclass. However,dataclasses.dataclass
expects anydataclass.Field
declared as an attribute (see alsodataclasses._get_field
). Nevertheless,pydantic.dataclasses._process_class
does not forward any field attribute to the new dataclass (line 144-154). Consequently, the new dataclass looses any field information on its attributes.Related
#2384
#2382
Affected Python Versions
This bug affects Python 3.9.1. Other python versions remain untested. However, it is very likely that other python versions are affected too.
Solution
Forward the original fields to the new dataclass. The example below solves the issue.
pydantic/dataclasses.py line 144-156
:Example Code
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: