Skip to content
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

Merged
merged 4 commits into from Jun 17, 2015

Conversation

erans
Copy link
Contributor

@erans erans commented Jun 16, 2015

No description provided.

@@ -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):
Copy link
Member

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

Copy link
Contributor Author

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 :-)

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

arikfr added a commit that referenced this pull request Jun 17, 2015
added Mongo JSON serializer to correctly serialize ObjectId + datetime.datetime serialization
@arikfr arikfr merged commit 5e351de into getredash:master Jun 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants