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

Keep values of private attributes set within model_post_init in subclasses #7775

Merged
merged 3 commits into from Oct 11, 2023

Conversation

alexmojaki
Copy link
Contributor

@alexmojaki alexmojaki commented Oct 9, 2023

Change Summary

Check for an existing __pydantic_private__ dict in init_private_attributes and account for values within, rather than always replacing with a new dict.

Related issue number

Fixes #7091

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @sydney-runkle

@alexmojaki
Copy link
Contributor Author

please review

@sydney-runkle
Copy link
Member

@alexmojaki,

Thanks so much for your contribution! Could you take a look at this comment when you have a chance?

Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Looks good otherwise 👍 just a small change request

pydantic/_internal/_model_construction.py Outdated Show resolved Hide resolved
@sydney-runkle
Copy link
Member

@dmontagu did you have a test change you wanted to add?

Copy link
Member

@sydney-runkle sydney-runkle 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 so much for this contribution 🌟.

@sydney-runkle
Copy link
Member

Note to myself, when I work on the #7656 task, I want to add a more robust test for this behavior.

@sydney-runkle sydney-runkle merged commit 218b5ad into pydantic:main Oct 11, 2023
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inheritance of Models with private attributes causes unexpected behavior via model_post_init
2 participants