-
Notifications
You must be signed in to change notification settings - Fork 292
Implement ser_json_temporal config option #1743
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
@davidhewitt think i've got most of the way with the serialization part, just a question: The pydantic PR mentions the new config option overlaps with ser_json_timedelta, which will be deprecated, but doesn't (at least i can't see where) how we want to handle the case where both are set. Do we want to do:
|
CodSpeed Performance ReportMerging #1743 will not alter performanceComparing Summary
|
Thanks! I would make it such that if That should make it non-breaking for existing users while adding the new preferred option. |
Right @davidhewitt, think i've implemented everything now. Got tests that show everything is working. Not 100% sure on my implementation on deciding between timedelta_mode and temporal_mode, but that should be all the serialisation work done? As a note the validation part of this seems a lot more complicated so may take a bit (lot) more time to implement.. hopefully supporting this first isn't too bad? |
please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the slow reply. I had to read this one a few times to pick through everything.
I'm happy with starting here, the validation is a separate option, after all. |
|
@davidhewitt actually, think i got the gist of it, didn't use the option in the end just create a method that turns the timedeltamode into a temporal mode for timedelta ser. Think this is everything resolved now |
@davidhewitt was there anything else you wanted me to have a look at here? |
Implements the first part of pydantic/pydantic#11504, which is the ser_json_temporal config option.
We now have a
ser_json_temporal
part to the config, which accepts ['iso8601', 'seconds', 'milliseconds']. These have been implemented as designed in the original pydantic pull request ('iso8601' being obvious, seconds and milliseconds each returning the number of seconds and milliseconds in a float).This has been done by implementing the serializers for each of the specified types (datetime, date, time, timedelta).
Special case for 'timedelta' where if the old config option is set, it will be used instead of ser_json_temporal.
Related issue number
pydantic/pydantic#11504
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @sydney-runkle