Pymongo regression - timezones are getting dropped when converting to JSON

Hey there,

Not sure if anyone is following this forum - and also not sure why there is no issue tracker on the github page:

but there is a major issue in the pymongo 4.1.1

Consider this string:

s = '{"event_type": "AM", "symbol": "TSLA", "s": {"$date": "2022-05-09T17:54:00Z"}, "t": {"$date": "2022-05-09T17:55:00Z"}, "av": 21049140, "op": 836.45, "vw": 802.2499, "o": 802.11, "h": 803.35, "l": 801.59, "c": 802.915, "v": 45151, "a": 817.3105, "z": 30, "received": {"$date": "2022-05-09T17:55:04.098Z"}}'

in python, when converting this to JSON using json_util and pymongo version 3.12.3

message = json_util.loads(s)

we get this:

{‘event_type’: ‘AM’,
‘symbol’: ‘TSLA’,
‘s’: datetime.datetime(2022, 5, 9, 17, 54, tzinfo=<bson.tz_util.FixedOffset object at 0x7f4298238040>),
‘t’: datetime.datetime(2022, 5, 9, 17, 55, tzinfo=<bson.tz_util.FixedOffset object at 0x7f4298238040>),
‘av’: 21049140,
‘op’: 836.45,
‘vw’: 802.2499,
‘o’: 802.11,
‘h’: 803.35,
‘l’: 801.59,
‘c’: 802.915,
‘v’: 45151,
‘a’: 817.3105,
‘z’: 30,
‘received’: datetime.datetime(2022, 5, 9, 17, 55, 4, 98000, tzinfo=<bson.tz_util.FixedOffset object at 0x7f4298238040>)}

however, when we use the latest version of pymongo v4.1.1

{‘event_type’: ‘AM’,
‘symbol’: ‘TSLA’,
‘s’: datetime.datetime(2022, 5, 9, 17, 54),
‘t’: datetime.datetime(2022, 5, 9, 17, 55),
‘av’: 21049140,
‘op’: 836.45,
‘vw’: 802.2499,
‘o’: 802.11,
‘h’: 803.35,
‘l’: 801.59,
‘c’: 802.915,
‘v’: 45151,
‘a’: 817.3105,
‘z’: 30,
‘received’: datetime.datetime(2022, 5, 9, 17, 55, 4, 98000)}

The timezones are missing!!!

Please fix this asap

Also, please remove this ugly green theme from the forum, it’s absolutely disgusting.

Also, please the issue tracker back on github, that’s where it belongs. I shouldn’t have to make an account on a forum just to post a bug report.

I can’t solve your problem, but the MongoDB issue tracker is here.