Skip to content
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

fix "extra fields not permitted" error when dataclass with Extra.forbid is validated multiple times #4354

Merged

Conversation

DetachHead
Copy link
Contributor

@DetachHead DetachHead commented Aug 9, 2022

Change Summary

if a dataclass gets validated multiple times by _dataclass_validate_values and has Extra.forbid in its config, it will fail validation as __pydantic_initialised__ is considered to be an invalid extra property.

i figured the safest fix for this (and any potential other similar issues) was to check whether the class has already been validated before validating it again.

Related issue number

fixes #4343

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@DetachHead DetachHead force-pushed the fix_extra_fields_not_permitted branch 2 times, most recently from 1419225 to 5e6720d Compare August 9, 2022 00:50
@DetachHead DetachHead force-pushed the fix_extra_fields_not_permitted branch from 5e6720d to 06f7de3 Compare August 9, 2022 01:17
@DetachHead
Copy link
Contributor Author

please review

Copy link
Member

@hramezani hramezani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@samuelcolvin
Copy link
Member

Sorry, I didn't realise the comment on the commit in the other repo would close this. 🙈

@samuelcolvin samuelcolvin enabled auto-merge (squash) August 11, 2022 10:59
@samuelcolvin
Copy link
Member

Thanks so much for this.

@samuelcolvin samuelcolvin merged commit 1e821b6 into pydantic:master Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants