Skip to content
Myr

Bugfix allow blueprints to be registered with a different name

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

This allows the same blueprint to be registered multiple times at the same level, but with differing url_prefixes and names.

authored by pgjones · committed by pgjones · parent 141fde1 · Browse files · 2 files+15 added−1 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+15 added−1 removed

  • tests:+13 added−0 removed
  • other:+2 added−1 removed

2 files+15 added−1 removed

modified:src/flask/blueprints.py+2 added-1 removed
272 unmodified lines
273 if blueprint is self:274 first_registration = False275276 name_prefix = options.get("name_prefix", "")277 self_name = options.get("name", self.name)277 name = f"{name_prefix}.{self.name}".lstrip(".")278 name = f"{name_prefix}.{self_name}".lstrip(".")279280 if name in app.blueprints and app.blueprints[name] is not self:281 raise ValueError(282 f"Blueprint name '{self.name}' "
288 unmodified lines
modified:tests/test_blueprints.py+13 added
864 unmodified lines
865 app.register_blueprint(parent, url_prefix=parent_registration)866867 response = client.get("/parent/child/")868 assert response.status_code == 200869870871def test_unique_blueprint_names(app, client) -> None:872 bp = flask.Blueprint("bp", __name__)873 bp2 = flask.Blueprint("bp", __name__)874875 app.register_blueprint(bp)876 app.register_blueprint(bp) # same name, same object, no error877878 with pytest.raises(ValueError):879 app.register_blueprint(bp2) # same name, different object880881 app.register_blueprint(bp2, name="alt") # different name