Add convert_decimal to CodecOptions

XMLWordPrintableJSON

    • 🔵 Done
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      We currently reject Python decimal instances and require the user to manually convert to Decimal128. We should investigate why we have this approach and consider encoding Python decimal instances by default.

      >>> bson.encode({"d": decimal.Decimal('1.0')})
      Traceback (most recent call last):
        File "<python-input-7>", line 1, in <module>
          encode({"d": decimal.Decimal('1.0')})
          ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 1053, in encode
          return _dict_to_bson(document, check_keys, codec_options)
      bson.errors.InvalidDocument: Invalid document {'d': Decimal('1.0')} | cannot encode object: Decimal('1.0'), of type: <class 'decimal.Decimal'>
      

      Related to INTPYTHON-497.

            Assignee:
            Noah Stapp
            Reporter:
            Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: