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
added Mongo JSON serializer to correctly serialize ObjectId + datetime.datetime serialization #455
Conversation
@@ -95,9 +95,9 @@ def default(self, o): | |||
if isinstance(o, decimal.Decimal): | |||
return float(o) | |||
|
|||
if isinstance(o, datetime.date): | |||
if isinstance(o, datetime.date) or isinstance(o, datetime.datetime): |
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.
Why is this needed?
>>> isinstance(datetime.datetime.now(), datetime.date)
True
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.
Mongo (and other runners) sometimes return a datetime.datetime object so I thought instead of having it in the mongodb json serializer I'll add it here.
datetime.date != datetime.datetime :-)
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.
From what I understand datetime.datetime
inherits datetime.date
, and hence why isinstance(datetime.datetime.now(), datetime.date) == True
. You see different behavior?
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.
Yet without this line the deserializer yells it cant deserialize
datetime.datetime.
That's why I added it.
On Tue, Jun 16, 2015, 21:40 Arik Fraimovich notifications@github.com
wrote:
In redash/utils.py
#455 (comment):@@ -95,9 +95,9 @@ def default(self, o):
if isinstance(o, decimal.Decimal):
return float(o)
if isinstance(o, datetime.date):
if isinstance(o, datetime.date) or isinstance(o, datetime.datetime):
From what I understand datetime.datetime inherits datetime.date, and
hence why isinstance(datetime.datetime.now(), datetime.date) == True. You
see different behavior?—
Reply to this email directly or view it on GitHub
https://github.com/EverythingMe/redash/pull/455/files#r32555487.
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.
OK. My bad. It accidentally called the original class. I'll remove it.
added Mongo JSON serializer to correctly serialize ObjectId + datetime.datetime serialization
No description provided.