Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support constraint application forBase64Etc 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sydney-runkle merged 3 commits intomainfrombytes-fix
Oct 11, 2024
Merged

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runklesydney-runkle commentedOct 9, 2024
edited
Loading

Alternative to#10500

Fixes#9251

Had to decouple (though, I view this as a sort of simplification) theEncodedBytes andEncodedStr dataclases. The API here feels a bit confusing- having theencoder separate from these types that define the pydantic methods seems overly complex.

Additionally, theEncodedStr type (unless I'm misunderstanding) does quite a large amount of encoding and decoding for both validation and serialization...

The main fix here is usinghandler(source) as the schema for the validator functions so that any constraints applied to the original type are respected.

@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelOct 9, 2024
@cloudflare-workers-and-pagesCloudflare Workers and Pages
Copy link

cloudflare-workers-and-pagesbot commentedOct 9, 2024
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:8b4f35d
Status: ✅  Deploy successful!
Preview URL:https://e998034b.pydantic-docs.pages.dev
Branch Preview URL:https://bytes-fix.pydantic-docs.pages.dev

View logs

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedOct 9, 2024
edited
Loading

CodSpeed Performance Report

Merging#10584 willnot alter performance

Comparingbytes-fix (8b4f35d) withmain (6c3d3b3)

Summary

✅ 38 untouched benchmarks

@@ -2580,7 +2593,7 @@ def decode_str(self, data: bytes, _: core_schema.ValidationInfo) -> str:
Returns:
The decoded data.
"""
return data.decode()
returnself.encoder.decode(data.encode()).decode()
Copy link
ContributorAuthor

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 astr, thenencode ->bytes,decode with ourencoder, thendecode back to astr? 🤮

Copy link
Contributor

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

@github-actionsGitHub Actions
Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  types.py
Project Total 

This report was generated bypython-coverage-comment-action

@sydney-runkle
Copy link
ContributorAuthor

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...

@sydney-runklesydney-runkle merged commit76222d2 intomainOct 11, 2024
61 checks passed
@sydney-runklesydney-runkle deleted the bytes-fix branchOctober 11, 2024 14:29
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dmontagudmontagudmontagu approved these changes

@ViicosViicosAwaiting requested review from Viicos

Assignees
No one assigned
Labels
relnotes-fixUsed for bugfixes.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Base64Bytes field doesn't raises validation error for min_length constraint
2 participants
@sydney-runkle@dmontagu

[8]ページ先頭

©2009-2025 Movatter.jp