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

Bump pydantic to 2.10.0 and remove Base64 workaround #73

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

facutuesca
Copy link
Collaborator

@facutuesca facutuesca commented Nov 20, 2024

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

@facutuesca facutuesca requested a review from woodruffw November 20, 2024 21:59
Comment on lines 616 to 631
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()
Copy link
Member

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 🙂

Copy link
Collaborator Author

@facutuesca facutuesca Nov 20, 2024

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.

@woodruffw
Copy link
Member

Thanks @facutuesca! One comment about keeping a test, otherwise LGTM.

Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
@facutuesca facutuesca force-pushed the ft/remove-pydantic-workaround branch from dece973 to 09f3ca8 Compare November 20, 2024 22:21
Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

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

LGTM!

@woodruffw woodruffw merged commit 5a50381 into main Nov 20, 2024
7 checks passed
@woodruffw woodruffw deleted the ft/remove-pydantic-workaround branch November 20, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants