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

datetime microseconds are rounded instead of truncated

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.7.1, 3.8
    • BSON
    • None
    • AWS Lambda (Python 3.6.1)
      pymongo 3.7.0

    Description

      datetime objects have a microsecond precision but the dates stored in MongoDB have a millisecond precision, so the value is truncated.

      But some dates may be rounded up instead on AWS Lambda (Python 3.6.1).
      3000-01-01 01:01:01.999999 is rounded up to 3000-01-01 01:01:02
      while
      3000-01-01 01:01:01.999900 or
      2000-01-01 01:01:01.999999 are truncated.

      It is due to a loss of precision in float operations on that platform when the internal representation exceeds a certain size.
      The conversion to milliseconds code can truncate the microsecond part before adding it to the number of seconds since the epoch to avoid the issue.

      Notes:

      • This issue did not appear on Linux with Python 3.6.1.
      • The datetime.timestamp() standard library method on AWS Lambda has the same rounding issue.

      Attachments

        Issue Links

          Activity

            People

              shane.harvey@mongodb.com Shane Harvey
              yves.duhem Yves Duhem
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: