-
Type: Question
-
Resolution: Works as Designed
-
Priority: Critical - P2
-
None
-
Affects Version/s: 4.1.1
-
Component/s: None
-
None
json_util.loads() is dropping timezones when using pymongo 4.1.1
To reproduce - 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"}}'
when using 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 using pymongo 4.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 tzinfo fields are getting dropped.
Please fix asap!
- is caused by
-
PYTHON-1949 CodecOptions and JSONOptions should have the same default value for tz_aware
- Closed