{"record":{"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":"exception","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/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/sansio/blueprints.py#L292-L328","documentation":"During register(), Flask computes the final blueprint name (name_prefix.name) and checks app.blueprints for collisions. If the resolved name is already present, it raises ValueError and tells the user to pass name= to disambiguate. This supports registering the same blueprint multiple times under unique names.","triggerScenarios":"Calling app.register_blueprint(bp) twice without a unique name/name_prefix; registering two different blueprints that resolve to the same dotted name; registering the same blueprint in a loop.","commonSituations":"Mounting one blueprint at multiple URL prefixes (must supply name= each time); wildcard/blueprint factories producing colliding names; reloading modules that re-run registration.","solutions":["Pass a unique name (or name_prefix) on each registration: app.register_blueprint(bp, name_prefix='v2') or name='admin2'.","Register each distinct blueprint only once under its own default name.","Guard against double registration by checking `if bp.name not in app.blueprints`."],"exampleFix":"// before\napp.register_blueprint(admin_bp, url_prefix='/admin')\napp.register_blueprint(admin_bp, url_prefix='/admin2')  # raises\n\n// after\napp.register_blueprint(admin_bp, url_prefix='/admin')\napp.register_blueprint(admin_bp, url_prefix='/admin2', name='admin2')","handlingStrategy":"validation","validationCode":"def resolve_bp_name(app, bp, options) -> str:\n    name_prefix = options.get('name_prefix', '')\n    self_name = options.get('name', bp.name)\n    name = f'{name_prefix}.{self_name}'.lstrip('.')\n    if name in app.blueprints:\n        raise ValueError(f'blueprint name {name!r} already taken; pass name=')\n    return name\n","typeGuard":"def bp_name_is_unique(app, name: str) -> bool:\n    return name not in app.blueprints\n","tryCatchPattern":"try:\n    app.register_blueprint(bp, url_prefix='/v2')\nexcept ValueError as e:\n    if 'already registered' in str(e):\n        app.register_blueprint(bp, url_prefix='/v2', name='bp_v2')\n    else:\n        raise","preventionTips":["When mounting the same blueprint multiple times, always pass a unique name=.","Log app.blueprints keys after each registration to spot collisions.","Avoid re-registering blueprints during hot-reload."],"tags":["flask","blueprint","registration","duplicate","naming"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}