{"id":"6031740d93dbafef","repo":"pallets/flask","slug":"the-name-self-name-is-already-registered-for","errorCode":null,"errorMessage":"The name '{self_name}' is already registered for {bp_desc} blueprint{existing_at}. Use 'name=' to provide a unique name.","messagePattern":"The name '(.+?)' is already registered for (.+?) blueprint(.+?)\\. Use 'name=' to provide a unique name\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/flask/sansio/blueprints.py","lineNumber":310,"sourceCode":"            Nested blueprints are registered with their dotted name.\n            This allows different blueprints with the same name to be\n            nested at different locations.\n\n        .. versionchanged:: 2.0.1\n            The ``name`` option can be used to change the (pre-dotted)\n            name the blueprint is registered with. This allows the same\n            blueprint to be registered multiple times with unique names\n            for ``url_for``.\n        \"\"\"\n        name_prefix = options.get(\"name_prefix\", \"\")\n        self_name = options.get(\"name\", self.name)\n        name = f\"{name_prefix}.{self_name}\".lstrip(\".\")\n\n        if name in app.blueprints:\n            bp_desc = \"this\" if app.blueprints[name] is self else \"a different\"\n            existing_at = f\" '{name}'\" if self_name != name else \"\"\n\n            raise ValueError(\n                f\"The name '{self_name}' is already registered for\"\n                f\" {bp_desc} blueprint{existing_at}. Use 'name=' to\"\n                f\" provide a unique name.\"\n            )\n\n        first_bp_registration = not any(bp is self for bp in app.blueprints.values())\n        first_name_registration = name not in app.blueprints\n\n        app.blueprints[name] = self\n        self._got_registered_once = True\n        state = self.make_setup_state(app, options, first_bp_registration)\n\n        if self.has_static_folder:\n            state.add_url_rule(\n                f\"{self.static_url_path}/<path:filename>\",\n                view_func=self.send_static_file,  # type: ignore[attr-defined]\n                endpoint=\"static\",\n            )","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/pallets/flask/blob/6a2f545bfd8ed31e19066a299296917e034aca58/src/flask/sansio/blueprints.py#L292-L328","documentation":"A ValueError from `Blueprint.register` (src/flask/sansio/blueprints.py:306-314), raised while an app (or parent blueprint) mounts this blueprint. The final registered name — `name_prefix + '.' + (options['name'] or self.name)` — must be unique in `app.blueprints` because it namespaces endpoints for `url_for`. Since Flask 2.1, registering the same name twice is a hard error; the message distinguishes whether the collision is with 'this' (same object registered twice) or 'a different' blueprint that happens to share the name.","triggerScenarios":"Calling `app.register_blueprint(bp)` twice for the same object without a distinguishing `name=`; registering two different Blueprint objects constructed with the same name string; nested registration where `name_prefix` makes two children resolve to the same dotted name; a `create_app()` or module-level registration executing twice (double import, test re-using a module-level app).","commonSituations":"Test suites registering blueprints onto a shared app across tests; wanting the same blueprint mounted at two URL prefixes (supported, but each mount needs a unique `name=`); two plugins/extensions each shipping a blueprint named e.g. 'auth'; upgrading from Flask <2.1 where silent double registration was tolerated.","solutions":["If mounting the same blueprint multiple times is intentional, give each registration a unique name: `app.register_blueprint(bp, url_prefix='/v2', name='api_v2')` — endpoints then use that name in `url_for`.","If it's accidental double registration, remove the duplicate call — check for `create_app()` running twice or registration at both module import and factory time.","If two distinct blueprints collide, rename one at construction or pass `name=` at registration."],"exampleFix":"# before\napp.register_blueprint(api, url_prefix=\"/v1\")\napp.register_blueprint(api, url_prefix=\"/v2\")  # ValueError\n\n# after\napp.register_blueprint(api, url_prefix=\"/v1\")\napp.register_blueprint(api, url_prefix=\"/v2\", name=\"api_v2\")","handlingStrategy":"validation","validationCode":"if bp.name in app.blueprints:\n    app.register_blueprint(bp, name=f'{bp.name}_2', url_prefix='/v2')\nelse:\n    app.register_blueprint(bp)","typeGuard":"def bp_name_free(app, name):\n    return name not in app.blueprints","tryCatchPattern":"try:\n    app.register_blueprint(bp)\nexcept ValueError as e:\n    if 'already registered' in str(e):\n        app.register_blueprint(bp, name=f'{bp.name}_{suffix}')","preventionTips":["To register the same blueprint twice (e.g. different url_prefix), always pass a unique name= per registration","Check app.blueprints before registering in plugin/loader code","Ensure module import side effects don't register the same blueprint more than once (watch out for double imports)"],"tags":["flask","python","blueprints","registration","naming"],"analyzedSha":"6a2f545bfd8ed31e19066a299296917e034aca58","analyzedAt":"2026-07-31T19:13:49.921Z","schemaVersion":2}