New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pydantic dataclasses do not respect the extra-fields in Config #986
Comments
This is a limitation of the standard dataclass implementation which pydantic uses, hence you can see the error is I don't see a way around this since AFAIK dataclasses don't have an "allow extra arguments" option. We should improve the documentation to describe which parts of |
|
@samuelcolvin thanks for the quick response. It makes complete sense. I suppose it would be possible to support this use case by filtering out fields that are not declared in the dataclass before instantiating the dataclass object though? |
I guess. We might also want to respect aliases by mapping them to field names. The problem is We create a vanilla dataclass and I don't know of a way to intercept a dataclass "pre-init". Also we'd then have to implement our own logic to map args to kwargs. To me this sounds unnecessarily complicated. If you want |
I guess we could do something like this |
why was this closed? looks like @PrettyWood's solution is simple enough |
At the very least the docs should mention that the |
can this be closed now that #2557 was merged? |
Question
Pydantic dataclasses do not seem to respect the configuration passed in the
@dataclass
-decorator. I am wondering if this is a bug or expected functionality? The documentation indicates that theConfig
is respected.In particular I would like to ignore extra fields when initialising the object. The documentation suggests that the default behaviour is
Extra.ignore
, but it does not seem to work. Making this explicit does not seem to have an effect either..Please complete:
The text was updated successfully, but these errors were encountered: