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

bulk_write does not apply CodecOptions to upserted_ids result

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.13, 4.1, 4.0.2
    • Affects Version/s: None
    • Component/s: None
    • None

      bulk_write does not apply CodecOptions to upserted_ids result:

      client = MongoClient(uuidRepresentation='standard')
      collection = client.test.test
      # normal insertion gives UUID representation
      result = collection.insert_one({'_id': uuid.uuid4()})
      result.inserted_id
      >>> UUID('1ec97f53-b1ae-471b-9e0c-157ca9b02953')
      doc = {'_id': uuid.uuid4()}
      result = collection.replace_one(doc, doc, upsert=True)
      result.upserted_id
      >>> UUID('c03ba52b-e594-47ca-8f12-249ae8eabf05')
      # bulk gives binary representation (this is the bug)
      doc = {'_id': uuid.uuid4()}
      result = collection.bulk_write([ReplaceOne(doc, doc, upsert=True)])
      result.upserted_ids
      >>> {0: Binary(b'\xb6\r%\xf2\xadOMo\x919\xc4\x98P\xe5\n\x02', 4)}
      

      Reported here https://www.mongodb.com/community/forums/t/uuid-representation-mismatch-with-pymongo-4-0-1/143570

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: