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
When defining dataclasses inside dataclasses, and then using those top-level dataclasses in pydantic models, I'm sometimes getting a TypeError: non-default argument '...' follows default argument.
Removing definitions of child dataclasses makes the code work properly.
Example Code
fromtypingimportOptional, Listfromdataclassesimportdataclass, fieldfrompydanticimportBaseModel@dataclassclassFoo:
a: Optional[int] =field(default=42)
b: List=field(default_factory=list)
@dataclassclassBar:
pass@dataclassclassModel1:
foo: Fooprint(Model1(foo=Foo())) # Model(foo=Foo(a=42, b=[]))classModel2(BaseModel):
foo: Fooprint(Model2(foo=Foo())) # TypeError: non-default argument 'b' follows default argument# Removing the definition of `Foo.Bar` makes this work properly.
Initial Checks
Description
When defining dataclasses inside dataclasses, and then using those top-level dataclasses in pydantic models, I'm sometimes getting a
TypeError: non-default argument '...' follows default argument
.Removing definitions of child dataclasses makes the code work properly.
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: