Skip to content

Implement val_temporal_unit for deciding how datetimes and dates timestamps get validated. #1751

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ollz272
Copy link
Contributor

@ollz272 ollz272 commented Jun 30, 2025

Change Summary

Follow up to #1743 and a part of pydantic/pydantic#11504 implementation - allows the config switch val_temporal_unit to be used to determine how dates and datetimes timestamps are validated - either as seconds, milliseconds, or inferred.

NOTE - the original ticket makes mention of this also working for time and duration. As far as i can see, we do not currently infer the value of these, they're just assumed to be seconds. Theres no support for this in speedate anyway. So I've implemented what is currently possible. I see 3 possible outcomes from this:

  1. We decide that this is fine for all time and this only supports date/datetime
  2. We decide that it should support time/duration, but its fine to get this part done first and add support for those later
  3. We decide that it should support time/duration, and it needs to go in at the same time.

Related issue number

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: @davidhewitt

Copy link

codecov bot commented Jun 30, 2025

Copy link

codspeed-hq bot commented Jun 30, 2025

CodSpeed Performance Report

Merging #1751 will not alter performance

Comparing ollz272:val_temporal_unit_2 (e476efb) with main (d523cf5)

Summary

✅ 157 untouched benchmarks

@ollz272
Copy link
Contributor Author

ollz272 commented Jul 1, 2025

Note - added a test here as this is the pr I discovered the issue with fractional millisecond timestamps (pydantic/pydantic#12027)

@ollz272
Copy link
Contributor Author

ollz272 commented Jul 1, 2025

Please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants