-
Notifications
You must be signed in to change notification settings - Fork 238
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
KeyError during import when running with python optimisation level of 2 #557
Comments
this should work for your application: if __debug__:
from cerberus import Validator
else:
from cerberus import UnconcernedValidator as Validator the latter import isn't depending on a valid schema and hence not the docstrings. and i think we can add this logic to the package's |
@funkyfuture, Fails with the same error. Import fails when executing https://github.com/pyeve/cerberus/blob/1.3.x/cerberus/__init__.py#L15 |
thanks for trying out my guess. i directly pushed a fix to the |
@funkyfuture, import is working fine on 1.3.x branch with python optimisation level 2. Thank you. |
thanks for your feedback. |
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. |
Used Cerberus version / latest commit: 1.3.2
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:
Error:
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?The text was updated successfully, but these errors were encountered: