Repository navigation
Fix datetime serialization - #84
Merged
Merged
Conversation
Member
|
@followben thank you for the patch and the detailed explanation of the problem 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
stream.py encodes dates to the Stream API using
isoformat()which drops microseconds if they are zero. However on decoding from the Stream API, stream.py expects microseconds to exist.In most instances, calling
datetime.now()will provide non-zero microseconds. However where an activity is created with datetime values set by a user (from the date widget in Django's admin panel for instance), microseconds will not exist. These fields will be currently be deserialized (incorrectly) as strings by stream.py.This PR adds extra logic to the serializer test case to verify the issue, and updates serialization to use the same string format for reading and writing datetime objects. I could have kept isoformat and specified
obj.isoformat(sep='T', timespec='microseconds'), but that arg is only available in Python 3.6+. Instead I've usedstrftimewhen writing to mirror the existing use ofstrptimewhen reading.Submitter checklist:
CHANGELOGupdated or N/AMerger checklist: