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

Fix strict behavior for unions #1638

Merged
merged 4 commits into from
Feb 25, 2025
Merged

Fix strict behavior for unions #1638

merged 4 commits into from
Feb 25, 2025

Conversation

sydney-runkle
Copy link
Member

@sydney-runkle sydney-runkle commented Feb 18, 2025

We currently don't allow the application of the strict constraint to Union types in pydantic. We should defer to either the runtime strict specification or the union choice strict specification.

strict can either be specified at runtime via the strict flag to model_validate_X, on a model's config, or on the union member type.

This fixes pydantic/pydantic#10571 by reflecting that pattern in pydantic-core.

Copy link

codspeed-hq bot commented Feb 18, 2025

CodSpeed Performance Report

Merging #1638 will not alter performance

Comparing fix-strict-for-unions (cef51f9) with main (bd0bde2)

Summary

✅ 157 untouched benchmarks

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

This seems fine to me; the union is just a simple combination of inner validators, and really it is their configuration which matters.

src/url.rs Outdated
@@ -400,7 +400,7 @@ impl PyMultiHostUrl {
username: username.map(Into::into),
password: password.map(Into::into),
host: host.map(Into::into),
port: port.map(Into::into),
port,
Copy link
Member Author

Choose a reason for hiding this comment

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

linting fix due to new clippy version :)

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

LGTM! Rebasing should fix the wasm build issue.

@sydney-runkle sydney-runkle enabled auto-merge (squash) February 25, 2025 13:38
@sydney-runkle sydney-runkle merged commit c40a138 into main Feb 25, 2025
27 of 28 checks passed
@sydney-runkle sydney-runkle deleted the fix-strict-for-unions branch February 25, 2025 13:41
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.

Unable to apply constraint 'strict' to schema of type 'union'
2 participants