Raise an error when deleting frozen (model) fields#7800
Merged
sydney-runkle merged 2 commits intopydantic:mainfrom Oct 12, 2023
Merged
Raise an error when deleting frozen (model) fields#7800sydney-runkle merged 2 commits intopydantic:mainfrom
sydney-runkle merged 2 commits intopydantic:mainfrom
Conversation
alexmojaki
commented
Oct 11, 2023
Contributor
Author
|
please review |
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. |
1 task
dmontagu
approved these changes
Oct 12, 2023
Contributor
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' |
Contributor
There was a problem hiding this comment.
Thanks for making sure to add a docs update as well 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Selected Reviewer: @dmontagu