-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support constraint application for Base64Etc types
#10584
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
Conversation
Deploying pydantic-docs with
|
| Latest commit: |
8b4f35d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e998034b.pydantic-docs.pages.dev |
| Branch Preview URL: | https://bytes-fix.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #10584 will not alter performanceComparing Summary
|
| @@ -2580,7 +2593,7 @@ def decode_str(self, data: bytes, _: core_schema.ValidationInfo) -> str: | |||
| Returns: | |||
| The decoded data. | |||
| """ | |||
| return data.decode() | |||
| return self.encoder.decode(data.encode()).decode() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that I understand the intent here - we validate a str, then encode -> bytes, decode with our encoder, then decode back to a str? 🤮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, since the encoder operates on bytes I think you need to do this if you want to apply it to strings
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
I think this is the right behavior, but if we have any issues with this type in v2.10, this would be the PR to revisit. Seems pretty low stakes, though... |
Alternative to #10500
Fixes #9251
Had to decouple (though, I view this as a sort of simplification) the
EncodedBytesandEncodedStrdataclases. The API here feels a bit confusing- having theencoderseparate from these types that define the pydantic methods seems overly complex.Additionally, the
EncodedStrtype (unless I'm misunderstanding) does quite a large amount of encoding and decoding for both validation and serialization...The main fix here is using
handler(source)as the schema for the validator functions so that any constraints applied to the original type are respected.