Skip to content

Commit

Permalink
Fix blueprint self registration
Browse files Browse the repository at this point in the history
By raising a ValueError if attempted. I don't see a use case that
makes this worth supporting.
  • Loading branch information
pgjones committed May 21, 2021
1 parent 9409be6 commit 714b0a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/flask/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def register_blueprint(self, blueprint: "Blueprint", **options: t.Any) -> None:
.. versionadded:: 2.0
"""
if blueprint is self:
raise ValueError("Cannot register a blueprint on itself")
self._blueprints.append((blueprint, options))

def register(self, app: "Flask", options: dict) -> None:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,9 @@ def test_unique_blueprint_names(app, client) -> None:
app.register_blueprint(bp2) # different bp, same name, error

app.register_blueprint(bp2, name="alt") # different bp, different name, ok


def test_self_registration(app, client) -> None:
bp = flask.Blueprint("bp", __name__)
with pytest.raises(ValueError):
bp.register_blueprint(bp)

0 comments on commit 714b0a4

Please sign in to comment.