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

Add guidance for setting uuidRepresentation in 4.0 migration guide

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.4
    • Affects Version/s: None
    • Component/s: Docs
    • Labels:
      None

      The migration guide describes the breaking 4.0 uuidRepresentation change (PYTHON-2245) like this:

      The default uuid_representation for CodecOptions, JSONOptions, and MongoClient has been changed from bson.binary.UuidRepresentation.PYTHON_LEGACY to bson.binary.UuidRepresentation.UNSPECIFIED. Attempting to encode a uuid.UUID instance to BSON or JSON now produces an error by default. See Handling UUID Data for details.

      https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html#encoding-a-uuid-raises-an-error-by-default

      We should add guidance for how applications should decide to set uuidRepresentation when upgrading. Something like:
      bq Applications that already store UUIDs in MongoDB using the PyMongo 3 default behavior need to set uuidRepresentation=pythonLegacy in the connection string. If they don't store UUIDs then they should set uuidRepresentation=standard.

      We should also include an example error:

      ValueError: cannot encode native uuid.UUID with UuidRepresentation.UNSPECIFIED. UUIDs can be manually converted to bson.Binary instances using bson.Binary.from_uuid() or a different UuidRepresentation can be configured. See the documentation for UuidRepresentation for more information.
      

            Assignee:
            julius.park@mongodb.com Julius Park (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: