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

BSON encoder/decoder is breaking on dates before 1-1-1970 with microsecond resolution

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.2
    • Component/s: None
    • Environment:
      debian squeeze 64
      linux 2.6.32-5-amd64

      Description

      Code:

      import bson
      from datetime import datetime

      my_date = datetime(1965, 1, 1, 15, 48, 57, 500340)
      my_dict =

      {'my_date': my_date}

      my_bson = bson.BSON.encode(my_dict)

      print my_bson.decode(tz_aware=False)
      print my_bson.decode(tz_aware=True)

      Output:

      {u'my_date': datetime.datetime(1965, 1, 1, 15, 48, 58, 16277216)}
        • Notice that the above datetime is not even valid as the microseconds field is far too large
        • Also: the call does not fail on tz_aware=False, however it does on tz_aware=True as shown below.

      Traceback (most recent call last):
      File "bsonbug.py", line 10, in <module>
      print my_bson.decode(tz_aware=True)
      File "/usr/local/lib/python2.6/dist-packages/bson/_init_.py", line 558, in decode
      (document, _) = _bson_to_dict(self, as_class, tz_aware)
      ValueError: microsecond must be in 0..999999

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: