-
Notifications
You must be signed in to change notification settings - Fork 2
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
Bump pydantic to 2.10.0 and remove Base64 workaround #73
Conversation
test/test_impl.py
Outdated
class DummyModel(BaseModel): | ||
base64_bytes: impl.Base64Bytes | ||
|
||
|
||
class TestBase64Bytes: | ||
# See the docstrings for `_impl.Base64Bytes` for more details | ||
def test_decoding(self) -> None: | ||
# This raises when using our custom type. When using Pydantic's Base64Bytes, | ||
# this succeeds | ||
# The exception message is different in Python 3.9 vs >=3.10 | ||
with pytest.raises(ValueError, match="Non-base64 digit found|Only base64 data is allowed"): | ||
DummyModel(base64_bytes=b"a\n\naaa") | ||
|
||
def test_encoding(self) -> None: | ||
model = DummyModel(base64_bytes=b"aaaa" * 76) | ||
assert "\\n" not in model.model_dump_json() |
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.
Can we keep this backstop test, but with the upstream Base64Bytes
? I don't expect them to regress here, but it's a good regression test to have in case they do 🙂
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.
done! I only kept the encoding test, since it's the one we care about. The difference in behavior for decoding was only due to me using validate=true
when calling b64decode(validate=True)
, which Pydantic now doesn't in their new implementation.
Thanks @facutuesca! One comment about keeping a test, otherwise LGTM. |
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
dece973
to
09f3ca8
Compare
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.
LGTM!
Now that
pydantic
2.10.0 was released with the fix for pydantic/pydantic#9072, this PR removes the workaround implemented in #48.Relevant entry in the release notes: https://pydantic.dev/articles/pydantic-v2-10-release#use-b64decode-and-b64encode-for-base64bytes-and-base64str-types