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

Support overflow integers in fallback_encoder

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.5
    • Affects Version/s: None
    • Component/s: None
    • None

      Raised by @stephan-hof on GitHub, https://github.com/mongodb/mongo-python-driver/pull/1243

      I'm regularly dealing with 64-bit unsigned integers.
      Those range from [0, (2**64) - 1]. So they are outside of the 64-bit signed integers from BSONs "\x12" e_name int64 64-bit integer.

      Up to now pymongo rejects those immediately with an OverflowError so the application must deal with them.
      For us this is pretty cumbersome, since we have a pretty complex structure and finding those large numbers would mean to 'traverse' through the whole document before giving it to pymongo.

      Performance and code wise this is not very ideal so my thinking was:
      To convert the document to BSON, pymongo must traverse the document anyway.
      So lets handle this 'big integer' like any other unknown type and call the fallback_encoder (if given).
      Then let the fallback_encoder deal with it. This is now up to me, like it is already with unknown types.

      In other words: If pymongo/bson detects an integer outside its supported range the fallback_encoder gets called.
      If no fallback_encoder is given or if fallback_encoder gives back a 'big integer' again the usual OverflowError is thrown.

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: