Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3259

Timezones are getting dropped when converting to JSON

    • Type: Icon: Question Question
    • Resolution: Works as Designed
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 4.1.1
    • Component/s: None
    • Labels:
      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!

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            goklani.vishal@gmail.com Vishal Goklani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: