KeyError during import when running with python optimisation level of 2
See original GitHub issueUsed Cerberus version / latest commit: 1.3.2
- I have the capacity to improve the docs when my problem is solved.
- I have the capacity to submit a patch when a bug is identified.
- My question does not concern a practical use-case that I can’t figure out to solve.
Use-case abstract
Firstly, this is a great package, this has saved a lot of my time in handling JSON payload validations. Thanks.
I’m using this in a Flask application and in development environment everything works as expected. However, when I try this on staging environment(where I run with python optimisation level of 2) import fails with a KeyError
Bug report
Python versions tried on: 3.8.5 and 3.6.6
To reproduce, run:
$ python -OO -c 'import cerberus'
Error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "cerberus/__init__.py", line 15, in <module>
from cerberus.validator import DocumentError, Validator
File "cerberus/validator.py", line 1615, in <module>
Validator = InspectedValidator('Validator', (BareValidator,), {})
File "cerberus/validator.py", line 1566, in __init__
x = cls.validation_rules['check_with']['oneof']
KeyError: 'oneof'
Looks like this is because doc strings won’t be available when running with optimisation level of 2 and I can see use of doc strings in __get_rule_schema
and few other functions.
At least for __get_rule_schema
use case, it can be obtained from a dictionary instead of relying on doc strings, not sure of other use cases. Not sure how should I proceed with this. Any suggestions?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
sorry, it turned out that the fix for this issue caused more trouble than it solved (see #567).
i’m gonna reverse the fix and instead let Cerberus raise a runtime error when Python is invoked with optimization level 2. the architecture of the 1.x series is just depending from doc strings.
thanks for your feedback.