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

Handlers are called in wrong order when using nested blueprints #4229

Closed
matipau opened this issue Aug 9, 2021 · 0 comments · Fixed by #4230
Closed

Handlers are called in wrong order when using nested blueprints #4229

matipau opened this issue Aug 9, 2021 · 0 comments · Fixed by #4230
Milestone

Comments

@matipau
Copy link

matipau commented Aug 9, 2021

When using nested blueprints, handlers registered via url_value_preprocessor, before_request, context_processor, or url_defaults are called in an inconsistent order: First on the app, then on the deepest blueprint, and then upwards through all parents (except the app). Here is a minimal example:

from flask import Flask, Blueprint, g

app = Flask(__name__)
parent = Blueprint('parent', __name__)
child = Blueprint('child', __name__)

@app.before_request
def app_before():
    g.test = 'app'

@parent.before_request
def parent_before():
    g.test = 'parent'

@child.before_request
def child_before():
    g.test = 'child'

@child.route('/')
def test():
    return g.test

parent.register_blueprint(child)
app.register_blueprint(parent)

I would expect this to return child, but it returns parent.

Environment:

  • Python version: 3.9.6
  • Flask version: 2.0.1
@davidism davidism added this to the 2.0.2 milestone Oct 4, 2021
@davidism davidism closed this as completed Oct 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants