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

bson.json_util does not properly serialize the UUID binary sub type

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible

      The UUID sub type should be encoded as

      { "$binary": "<bindata>", "$type": "<t>" }

      according to the documentation:
      https://docs.mongodb.com/manual/reference/mongodb-extended-json/#binary

      This is also what the server does: https://github.com/mongodb/mongo/blob/master/src/mongo/dbtests/jsontests.cpp#L1396

      Example of the current behavior

      >>> import bson
      >>> from bson import json_util
      >>> from bson.binary import UUID
      >>> json_util.dumps({'uuid': UUID('f47ac10b-58cc-4372-a567-0e02b2c3d479')})
      '{"uuid": {"$uuid": "f47ac10b58cc4372a5670e02b2c3d479"}}'
      

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

              Created:
              Updated:
              Resolved: