Gremlin Python converts timezone to local?

92 views
Skip to first unread message

Peter Dancso

unread,
Jul 9, 2019, 11:57:43 AM7/9/19
to Gremlin-users
Hi,
We are seeing some odd behaviour and would like to get some clarification on it.
We store some transactions in Neptune and all dates are stored as timezone aware UTC

gremlin> g.V("TRANSACTION42685288").valueMap()


==>{is_confirmed_fraud=[false], vertex_value=[42685288], created_date=[Thu Jul 04 11:38:45 UTC 2019], paid_date=[Thu Jul 04 11:43:38 UTC 2019]}


However when we use gremlin-python we get a timezone naive local time converted timestamp (BST in this case)
g.V("TRANSACTION42685288").valueMap().toList()

[{'vertex_value': [42685288],
 
'created_date': [datetime.datetime(2019, 7, 4, 12, 38, 45, 790000)],
 
'paid_date': [datetime.datetime(2019, 7, 4, 12, 43, 38)],
 
'is_confirmed_fraud': [False]}]

Could someone please clarify the exact behaviour? Is there any way to disable gremlin-python from doing this dangerous conversion?

Thanks,
Peter

Stephen Mallette

unread,
Jul 10, 2019, 8:02:49 PM7/10/19
to gremli...@googlegroups.com
Dates and times always find a way to get me confused. I'll lay out what I see. I assume Neptune is treating your date as a  g:Date in GraphSON which is bound to java.util.Date. It looks like Jackson writes Date as getTime():


 which is:


and here's the deserialization code for gremlin-python:


so if i'm reasoning properly, if java.util.Date has no timezone and its value is generally related to UTC, we should be changing gremlin-python to use datetime.utcfromtimestamp() rather than datetime.fromtimestamp() ? i wouldn't be surprised if i was suggesting the wrong fix. :)

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/867eeebe-b34d-42ed-b9ad-1ab1bacd0218%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Dancso

unread,
Jul 11, 2019, 5:35:32 AM7/11/19
to Gremlin-users
Hey Stephen,
First of all, thanks a lot for your response! I followed your logic and it all makes perfect sense now.

DateIO.objectify() converts to local date from the POSIX timestamp, without adding a timezone to the datetime object. (https://docs.python.org/2/library/datetime.html#datetime.date.fromtimestamp)

Your solution makes perfect sense to use utcfromtimestamp() instead. Should I make the change or will you do it? Do you have any idea when the fix could be released?
Thanks,
Peter 

To unsubscribe from this group and stop receiving emails from it, send an email to gremli...@googlegroups.com.

Stephen Mallette

unread,
Jul 11, 2019, 5:58:26 AM7/11/19
to gremli...@googlegroups.com
We'd be happy to accept a pull request for that if you'd like to do it. Please target the tp33 branch and maybe have a look at the current tests to see if they can be improved at all in this regard.


I don't know exactly when it will release, but we are coming up on our next release window at the end of July so I'd think you would see it in the next few weeks. Thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e282c404-3320-4905-aafb-38e358e72f54%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages