#1486·eve

etag generation fails if 'uuidRepresentation' is not set in MONGO_OPTIONS

Author: tgm-gitCreated Sep 21, 2022Updated Sep 21, 2022

This issue tracker is a tool to address bugs in Eve itself. Please use Stack Overflow for general questions about using Eve or issues not related to Eve (see http://python-eve.org/support).

If you'd like to report a bug in Eve, fill out the template below. Provide any any extra information that may be useful / related to your problem. Ideally, create an MCVE, which helps us understand the problem and helps check that it is not caused by something in your code.


Expected Behavior

When uuidRepresentation is not set in MONGO_OPTIONS generating etags should still be possible.

python

-- app.py
my_settings = {
    'MONGO_HOST': 'localhost',
    'MONGO_PORT': 27017,
    'MONGO_DBNAME': 'the_db_name',
    'DOMAIN': {'contacts': {}}
}

app = Eve(settings=my_settings)
app.run()


-- some_test.py
from eve import post_internal
post_internal('contacts', {'a_valid_contact': 'this must be'}, skip_validation=True)

Actual Behavior

Since no uuidRepresentation is present in MONGO_OPTIONS, the default option is selected, which is an int, not a string. A simple fix would be changing line 350 in eve/utils.py from config.MONGO_OPTIONS.get("uuidRepresentation", UuidRepresentation.STANDARD) to config.MONGO_OPTIONS.get("uuidRepresentation", "standard")

or add a field 4 to the uuid_map on line 343:

uuid_map = {
            "standard": UuidRepresentation.STANDARD,
            4: UuidRepresentation.STANDARD,
            "unspecified": UuidRepresentation.UNSPECIFIED,
            "pythonLegacy": UuidRepresentation.PYTHON_LEGACY,
            "csharpLegacy": UuidRepresentation.CSHARP_LEGACY,
            "javaLegacy": UuidRepresentation.JAVA_LEGACY,
        }
pytb
    def uuid_representation_as_string():
        uuid_map = {
            "standard": UuidRepresentation.STANDARD,
            "unspecified": UuidRepresentation.UNSPECIFIED,
            "pythonLegacy": UuidRepresentation.PYTHON_LEGACY,
            "csharpLegacy": UuidRepresentation.CSHARP_LEGACY,
            "javaLegacy": UuidRepresentation.JAVA_LEGACY,
        }
>       return uuid_map[
            config.MONGO_OPTIONS.get("uuidRepresentation", UuidRepresentation.STANDARD)
        ]
E       KeyError: 4

Environment

  • Python version: 3.9.2
  • Eve version: 2.0.1