uuidRepresentation issue in pymongo when passing a parameter to MongoClient

Hi community!
I have stumbled upon an issue working with uuidRepresentations in python module. I am updating an application to run the last version of pymongo (3.12.3 to 4.2.0). In the code snippet I am initializing a MongoClient object passing username, password, uri and uuidRepresentation as kwargs.

client = MongoClient(
                SOME_URI,
                user=user,
                pass=pass
                uuidRepresentation=UuidRepresentation.PYTHON_LEGACY
            )

However, when I check the properties of client object in debug I could see that the uuidRepresentation in codec_options is equal to 0 (UNSPECIFIED) and it looks like it is being set to default value somewhere inside pymongo, regardless of what uuidRepresentation parameter I passed to MongoClient constructor.
image.
What could be the cause of this issue and how to fix it properly?

Thanks in advance!

Hi @Oleksii_Anoshyn, I’m having a difficult time reproducing your problem. When I try with uuidRepresentation=UuidRepresentation.PYTHON_LEGACY, I get a traceback:

ValueError: 3 is an invalid UUID representation. Must be one of ('unspecified', 'standard', 'pythonLegacy', 'javaLegacy', 'csharpLegacy')

because it is expecting a string value and not an enum.

When I use uuidRepresentation='pythonLegacy', I get “3” for the value of client.codec_options.uuid_representation.

I also verified that a URI argument does not override the value given as a keyword (e.g. mongodb://localhost:27107/?uuidRepresentation=standard).

Are you able to give fully self-contained example code that reproduces the problem?

2 Likes