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 used strftime when writing to mirror the existing use of strptime when reading.
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 usedstrftime
when writing to mirror the existing use ofstrptime
when reading.Submitter checklist:
CHANGELOG
updated or N/AMerger checklist: