Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tgm-git opened this issue Sep 21, 2022 · 1 comment
Open

Comments

@tgm-git
Copy link
Contributor

tgm-git commented 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.

-- 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,
        }
    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
@tgm-git
Copy link
Contributor Author

tgm-git commented Sep 21, 2022

A workaround for this bug is to simply set uuidRepresentation to 'standard' in MONGO_OPTIONS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant