Skip to content

Commit 714b0a4

Browse files
committed
Fix blueprint self registration
By raising a ValueError if attempted. I don't see a use case that makes this worth supporting.
1 parent 9409be6 commit 714b0a4

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/flask/blueprints.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ def register_blueprint(self, blueprint: "Blueprint", **options: t.Any) -> None:
260260
261261
.. versionadded:: 2.0
262262
"""
263+
if blueprint is self:
264+
raise ValueError("Cannot register a blueprint on itself")
263265
self._blueprints.append((blueprint, options))
264266

265267
def register(self, app: "Flask", options: dict) -> None:

tests/test_blueprints.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,9 @@ def test_unique_blueprint_names(app, client) -> None:
883883
app.register_blueprint(bp2) # different bp, same name, error
884884

885885
app.register_blueprint(bp2, name="alt") # different bp, different name, ok
886+
887+
888+
def test_self_registration(app, client) -> None:
889+
bp = flask.Blueprint("bp", __name__)
890+
with pytest.raises(ValueError):
891+
bp.register_blueprint(bp)

0 commit comments

Comments
 (0)