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

Exceptions in before_request methods prevent later before_request methods from running #2821

Closed
skylerberg opened this issue Jun 10, 2018 · 1 comment

Comments

@skylerberg
Copy link

Expected Behavior

All methods added with @app.before_request should be run.

Paste a minimal example that causes the problem.

Actual Behavior

If an exception occurs in a single @app.before_request method, all following @app.before_request methods will not run.

Context

For a detailed example of this causing an issue, see GoogleCloudPlatform/flask-talisman#22.

In summary, Flask-Talisman does setup in an @app.before_request method which is expected to be done by the time it runs an @app.after_request method. However, if an exception occurs in an @app.before_request method that runs before Flask-Talisman's, and that exception is caught by an @app.errorhandler, then Flask-Talisman's @app.after_request method can be run without the setup work ever being done.

@davidism
Copy link
Member

Changing Flask's behavior would be incorrect, as before request handlers are allowed to exit early and return a response (an exception is a response). This would just cause all the before handlers that expect earlier handlers to run to fail too.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants