Fix failure to load SecretStr from JSON (regression in v2.4)#7729
Merged
Fix failure to load SecretStr from JSON (regression in v2.4)#7729
SecretStr from JSON (regression in v2.4)#7729Conversation
Deploying with
|
| Latest commit: |
662e0ed
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ae388ae4.pydantic-docs2.pages.dev |
| Branch Preview URL: | https://fix-secretstr-from-json-vali.pydantic-docs2.pages.dev |
Contributor
Author
|
Please review 😄 |
dmontagu
approved these changes
Oct 3, 2023
SecretStr from JSON (regression in v2.4)
davidhewitt
reviewed
Oct 3, 2023
Collaborator
davidhewitt
left a comment
There was a problem hiding this comment.
Overall looks like the right fix to me, two quick thoughts:
Comment on lines
+3930
to
+3933
| f1 = Foobar(password='1234', empty_password='') | ||
| f2 = Foobar.model_validate_json('{"password": "1234", "empty_password": ""}') | ||
|
|
||
| for f in [f1, f2]: |
Collaborator
There was a problem hiding this comment.
It may be slightly nicer to turn this into a parameterized test rather than have one of f1 or f2 fail inside the loop
| strict=True, | ||
| custom_error_type=error_kind, | ||
| ), | ||
| json_schema=json_schema, |
Collaborator
There was a problem hiding this comment.
This might want to have a custom_error_schema and use custom_error_type in some form on this branch. Possibly worth testing the JSON validation error with the wrong type.
Contributor
There was a problem hiding this comment.
(As discussed elsewhere,) I think given the specific format of the errors seems good (added to the test below), this isn't necessary.
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
Ensure that a
SecretStrtype can be populated from json.Related issue number
Fix #7720
Checklist
Selected Reviewer: @samuelcolvin