-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
Reloader fails to reload after SyntaxError when the app is in an __init__.py file #2423
Comments
Does this happen with current master? |
Yep. |
I've been able to verify this behaviour with current master and Pythons 2.7 and 3.6. On first request, On Python3.6 no
I'm assuming the desired behaviour is for Flask to forward errors that arise during importation rather than fail with |
A fix was released for the reloader failing in Werkzeug. The |
When a SyntaxError occurrs in a package's `__init__.py` file, Python seems to leave an empty module in `sys.modules`. This will result in any request after the first to give you a `NoAppException` instead of the `SyntaxError` again. Fixes pallets#2423
I can't reproduce this on Python 2.7 or 3.6, Flask 0.12 or master. I tried starting with valid syntax then editing in an error, and vice versa. |
Expected Behavior
The reloader should work correctly even for an app in a package's
__init__.py
file.In
hello/__init__.py
:Than edit
__init__.py
and introduce a syntax error.Actual Behavior
I get the SyntaxError the first time I try to browse and afterwards get:
Cause
This is caused by weird CPython behavior which might be a bug:
After the
SyntaxError
in the app, the Wekzeug reloader won't know about the__init__.py
file any more since it iteratessys.modules
and the entry there contains the path to the directory instead of the path to the__init__.py
file, and Flask will call__import__
repeatedly but will get the weird empty module and will fail to find an app in it, leading to the described exception.Environment
Not sure if this happens in Python 3.
The text was updated successfully, but these errors were encountered: