question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialized then deserialized Datetimes are not equal

See original GitHub issue

As 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
sloriacommented, Jul 4, 2019

@palango I’ve cut 3.0.0rc8 that has the relevant change.

0reactions
palangocommented, Jul 4, 2019

@lafrech I just ran into that problem. Can you maybe release a new RC with these fixes?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found