8000 Fix url serialization for unions by sydney-runkle · Pull Request #11227 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Fix url serialization for unions #11227

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

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Fix url serialization for unions #11227

merged 1 commit into from
Jan 8, 2025

Conversation

sydney-runkle
Copy link
Contributor
@sydney-runkle sydney-runkle commented Jan 7, 2025

Fix #11211

We want to make sure that non-url type data passed to url serialization logic raises a warning, just like we do for the custom ip types, see:

def ser_ip(ip: Any, info: core_schema.SerializationInfo) -> str | IpType:

This makes it such that serialization of data having union types like HttpUrl | str prefers the str type when appropriate.

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Jan 7, 2025
Copy link

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3faf897
Status: ✅  Deploy successful!
Preview URL: https://115555ee.pydantic-docs.pages.dev
Branch Preview URL: https://fix-url-ser.pydantic-docs.pages.dev

View logs

@sydney-runkle sydney-runkle requested a review from Viicos January 7, 2025 18:12
Copy link
codspeed-hq bot commented Jan 7, 2025

CodSpeed Performance Report

Merging #11227 will degrade performances by 22.46%

Comparing fix-url-ser (3faf897) with main (a2eb22b)

Summary

❌ 2 (👁 2) regressions
✅ 44 untouched benchmarks

Benchmarks breakdown

Benchmark main fix-url-ser Change
👁 test_north_star_dump_python 15.8 ms 18 ms -12.31%
👁 test_north_star_validate_python_strict 27.4 ms 35.3 ms -22.46%

Copy link
Contributor
github-actions bot commented Jan 7, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  networks.py 469-473
Project Total  

This report was generated by python-coverage-comment-action

@sydney-runkle sydney-runkle merged commit 5d92c05 into main Jan 8, 2025
62 checks passed
@sydney-runkle sydney-runkle deleted the fix-url-ser branch January 8, 2025 15:56
sydney-runkle added a commit that referenced this pull request Jan 8, 2025
Specifically, we've made the serialization for url types more strict. If a non-url type is passed into the serializer, we raise an unexpected value warning instead of just blindly attempting to stringify the input. This results in more intuitive behavior for serializing unions with url types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A strange new bug with HttpUrl in v2.10.4
2 participants
0