Serialized then deserialized Datetimes are not equal
See original GitHub issueAs a new user, I would expect the following code to work correctly:
from marshmallow import Schema, fields
from datetime import datetime as dt, timezone as tz
class User():
def __init__(self, datetime):
self.datetime = datetime
class UserSchema(Schema):
datetime = fields.DateTime()
user = User(dt.now())
serialized = UserSchema().dump(user).data
deserialized = UserSchema().load(serialized).data
assert user.datetime == deserialized['datetime']
Now since the DateTime field serializes differently when python-dateutil is available, there are two cases:
python-dateutil is available
The above will fail since the utc timezone is added to the serialized datetime, which was timezone unaware before serialization.
python-dateutil is not available
It will also fail in this case, since when python-dateutil is not available neither microsecond or timezone is deserialized in ISO format. They are however correctly serialized.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
scala - DateTime does not equal itself after unserialization
When you serialize and deserialize a java.util.Date the long (the wrapped value) is passed not a String. Share.
Read more >Roundtrip Serialization of DateTimes in C# - Mark Heath
Say you need to serialize a DateTime object to string (perhaps for an XML or JSON file), and want to ensure that you...
Read more >Problem when deserializing the Date - MSDN - Microsoft
String). If you declare it as DateTime, then the serializer now has more information, and it will deserialize it into a DateTime value....
Read more >Datetime deserialization is not working (serialization works fine)
I want java Date object to be serialized using following format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ" and read back from a string of the same format during ......
Read more >Web services serialization and deserialization troubleshooting ...
Time zone information in deserialized java.util. ... Because the time zone in a deserialized Calendar instance might not match the current ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@palango I’ve cut 3.0.0rc8 that has the relevant change.
@lafrech I just ran into that problem. Can you maybe release a new RC with these fixes?