default_factory
treated incorrectly, but only in presence of methods
#5065
Labels
default_factory
treated incorrectly, but only in presence of methods
#5065
Initial Checks
Description
I'm seeing an error very similar to #2555, where
pydantic
doesn't understand a field marked withdefault_factory
, thinking it's a non-default field, and thus complains it follows a default field. Reportedly that issue has been resolved in 1.10, but I am still observing it as long as some extra method exists in thedataclass
; then, the attached code results inCrucially, if the
fn
method is removed,pydantic
no longer reports an error.One can get around this by reordering the fields in the
dataclass
, but that affects the order of__init__
arguments, which is undesirable. Note that my code uses plaindataclasses
, notpydantic.dataclasses
; this is needed for compatibility with other code that does not usepydantic
.Example Code
Python, Pydantic & OS Version
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: