-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Description
The application initialization script uses and import with a side effect. The app.validators module is imported, which uses the jsonschema.draft4_format_checker decorator. It has a side effect of globally registering the validation function. That itself is not a very good thing, but it’s how this external library behaves.
Moreover this all happens not when the app is created (by the create_app function), but when the app module is imported. That makes the app module import itself having a side effect. No no no.
- Remove the decorator side effect
- Remove the import side effect
The decorators can be resolved by using them as a plain function. It doesn’t modify the original function in any way, it just registers it in the module.
# app.validators
@draft4_format_checker.checks('uuid')
…
def verify_uuid_format(uuid_str):
…
def register_validators():
validations = (
"uuid": verify_uuid_format
…
)
for name, func in validations:
validator = draft4_format_checker.checks(name)
validator(function)
…# app
…
from app.validators import register_validators
…
def create_app(config_name):
…
register_validators()
…
…Metadata
Metadata
Assignees
Labels
No labels