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
Hi all,
I am encountering an exception when I have a pydantic dataclass that inherits from a stdlib dataclass but has no additional fields. (I use the stdlib dataclass for internal usages and pydantic for validation.)
I don't know if my use case is dumb, regardless here is the error trace I encounter for the example code below.
Traceback (most recent call last):
File "/Users/username/Documents/Code/py/pydantic_bug/pydantic_dc_bug.py", line 22, in <module>
class ValidatedDerivedC(UnvalidatedDataclass):
File "pydantic/dataclasses.py", line 200, in pydantic.dataclasses.dataclass.wrap
# https://bugs.python.org/issue33453 for details.
AttributeError: 'NoneType' object has no attribute '__bases__'
This is not a showstopper for me.
I've discovered that using @pydantic.dataclasses.dataclass (no parentheses) instead of @pydantic.dataclasses.dataclass() avoids the error.
Adding a field to the derived class also avoids the error.
I am mostly adding this bug report for awareness.
If you need any additional help, I sorta understand why this is happening, but at the moment I'm not certain how to fix it without breaking other stuff.
Thank you for your work on this library. It is much appreciated!
Example Code
importdataclassesimportpydantic@dataclasses.dataclassclassUnvalidatedDataclass:
a: int=0#okay@pydantic.dataclasses.dataclassclassValidatedDerivedA(UnvalidatedDataclass):
...
#also okay@pydantic.dataclasses.dataclass()classValidatedDerivedB(UnvalidatedDataclass):
b: int=0#AttributeError: 'NoneType' object has no attribute '__bases__'@pydantic.dataclasses.dataclass()classValidatedDerivedC(UnvalidatedDataclass):
...
Initial Checks
Description
Hi all,
I am encountering an exception when I have a pydantic dataclass that inherits from a stdlib dataclass but has no additional fields. (I use the stdlib dataclass for internal usages and pydantic for validation.)
I don't know if my use case is dumb, regardless here is the error trace I encounter for the example code below.
This is not a showstopper for me.
I've discovered that using
@pydantic.dataclasses.dataclass
(no parentheses) instead of@pydantic.dataclasses.dataclass()
avoids the error.Adding a field to the derived class also avoids the error.
I am mostly adding this bug report for awareness.
If you need any additional help, I sorta understand why this is happening, but at the moment I'm not certain how to fix it without breaking other stuff.
Thank you for your work on this library. It is much appreciated!
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: