Skip to content
Myr

Fix blueprint self registration

Before adoption: this commit came in with the history the project adopted, so no landing records it.

By raising a ValueError if attempted. I don't see a use case that makes this worth supporting.

authored by pgjones · committed by pgjones · parent 9409be6 · Browse files · 2 files+8 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−0 removed

  • tests:+6 added−0 removed
  • other:+2 added−0 removed

2 files+8 added−0 removed

modified:src/flask/blueprints.py+2 added
258 unmodified lines
259 for ``url_for``.260261 .. versionadded:: 2.0262 """263 if blueprint is self:264 raise ValueError("Cannot register a blueprint on itself")265 self._blueprints.append((blueprint, options))266267 def register(self, app: "Flask", options: dict) -> None:268 """Called by :meth:`Flask.register_blueprint` to register all
333 unmodified lines
modified:tests/test_blueprints.py+6 added
881 unmodified lines
882 with pytest.raises(ValueError):883 app.register_blueprint(bp2) # different bp, same name, error884885 app.register_blueprint(bp2, name="alt") # different bp, different name, ok886887888def test_self_registration(app, client) -> None:889 bp = flask.Blueprint("bp", __name__)890 with pytest.raises(ValueError):891 bp.register_blueprint(bp)