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

Raise an error when deleting frozen (model) fields #7800

Merged
merged 2 commits into from Oct 12, 2023

Conversation

alexmojaki
Copy link
Contributor

@alexmojaki alexmojaki commented Oct 11, 2023

Change Summary

Extracted the validation logic for frozen fields/models in __setattr__ into a new method _check_frozen, deduplicated it a bit, and called it in __delattr__ which was previously incorrectly not checking this.

Related issue number

Closes #7784

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: @dmontagu

@alexmojaki
Copy link
Contributor Author

please review

@alexmojaki
Copy link
Contributor Author

@sydney-runkle I think it's interesting that the bot doesn't assign to you automatically since you were assigned to the linked issue.

@dmontagu dmontagu added the relnotes-fix Used for bugfixes. label Oct 12, 2023
@sydney-runkle
Copy link
Member

@sydney-runkle I think it's interesting that the bot doesn't assign to you automatically since you were assigned to the linked issue.

Indeed, we have some work to do with the hooky bot 😆

Comment on lines +735 to +740

try:
del model.x
except ValidationError as exc:
print(repr(exc.errors()[0]['type']))
#> 'frozen_field'
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for making sure to add a docs update as well 😄

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 as well 👍

@sydney-runkle sydney-runkle merged commit 4348153 into pydantic:main Oct 12, 2023
59 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attributes can be deleted from frozen models
3 participants