Skip to content

Conversation

@astei
Copy link
Contributor

@astei astei commented Oct 22, 2025

Change Summary

Modifies the pydantic-core serializers for date, datetime, time, and timedelta such that they perform their downcast checks first prior to performing any serialization logic. This fixes incorrect serialization with certain user-defined types and correctly emits warnings where we were incorrectly doing so ebfore.

Related issue number

Fixes pydantic/pydantic#12439

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @Viicos

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/serializers/type_serializers/datetime_etc.rs 0.00% 6 Missing ⚠️
src/serializers/type_serializers/timedelta.rs 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@astei astei force-pushed the astei/pull-downcast-dt-td-up branch from 1e8d318 to d6cc210 Compare October 22, 2025 21:18
@astei astei force-pushed the astei/pull-downcast-dt-td-up branch from d6cc210 to e5a373c Compare October 22, 2025 21:20
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 22, 2025

CodSpeed Performance Report

Merging #1851 will not alter performance

Comparing astei:astei/pull-downcast-dt-td-up (e5a373c) with main (396499c)

Summary

✅ 163 untouched

@astei astei changed the title Correct invalid serialization of date/datetime/time/timedelta by pulling instanceof checks up Correct invalid serialization of date/datetime/time/timedelta by pulling downcast checks up Oct 22, 2025
@astei
Copy link
Contributor Author

astei commented Oct 22, 2025

please review

@Viicos Viicos removed their assignment Oct 23, 2025
@Viicos Viicos requested a review from davidhewitt October 23, 2025 12:03
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.

Thanks, lgtm!

@davidhewitt davidhewitt merged commit eed392b into pydantic:main Oct 23, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants