{"id":"16b0e60d9b50309d","repo":"sqlalchemy/alembic","slug":"no-such-branch-s","errorCode":null,"errorMessage":"No such branch: '%s'","messagePattern":"No such branch: '(.+?)'","errorType":"exception","errorClass":"ResolutionError","httpStatus":null,"severity":"error","filePath":"alembic/script/revision.py","lineNumber":591,"sourceCode":"        full revision.\n\n        \"\"\"\n\n        resolved_id, branch_label = self._resolve_revision_number(id_)\n        if len(resolved_id) > 1:\n            raise MultipleHeads(resolved_id, id_)\n\n        resolved: str | tuple[()] = resolved_id[0] if resolved_id else ()\n        return self._revision_for_ident(resolved, branch_label)\n\n    def _resolve_branch(self, branch_label: str) -> Revision | None:\n        try:\n            branch_rev = self._revision_map[branch_label]\n        except KeyError:\n            try:\n                nonbranch_rev = self._revision_for_ident(branch_label)\n            except ResolutionError as re:\n                raise ResolutionError(\n                    \"No such branch: '%s'\" % branch_label, branch_label\n                ) from re\n\n            else:\n                return nonbranch_rev\n        else:\n            return branch_rev\n\n    def _revision_for_ident(\n        self,\n        resolved_id: str | tuple[()] | None,\n        check_branch: str | None = None,\n    ) -> Revision | None:\n        branch_rev: Revision | None\n        if check_branch:\n            branch_rev = self._resolve_branch(check_branch)\n        else:\n            branch_rev = None","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/script/revision.py#L573-L609","documentation":"Raised by _resolve_branch(branch_label) when the label is neither a registered branch label in the revision map nor resolvable as an ordinary revision. This is the underlying error behind 'branch@...' syntax that names a nonexistent branch. It is a ResolutionError.","triggerScenarios":"Issuing 'alembic upgrade nonexistentbranch@head', 'alembic downgrade mybranch@-1', or any API call passing a 'label@rev' string where label was never declared via branch_labels in a migration.","commonSituations":"Typo in a branch label; referencing a branch label that was removed when its migration was deleted; team members who don't have the branch-labeled migration checked out.","solutions":["List known branches: inspect the migration scripts for branch_labels assignments, or enumerate script.get_revisions('heads') and read .branch_labels.","Correct the label spelling or drop the 'branch@' prefix if you meant a plain revision.","If the branch migration was deleted, restore it or re-add the branch_labels to the appropriate revision."],"exampleFix":"# before\nalembic upgrade typobranch@head   # No such branch\n# after\nalembic upgrade correctbranch@head","handlingStrategy":"validation","validationCode":"known_labels = {\n    lbl\n    for r in script.walk_revisions()\n    for lbl in r.branch_labels\n}\nif branch_label not in known_labels:\n    raise ValueError('unknown branch label: %s' % branch_label)","typeGuard":null,"tryCatchPattern":"from alembic.script.revision import ResolutionError\ntry:\n    script.get_revision('%s@head' % branch_label)\nexcept ResolutionError as e:\n    # handle unknown branch\n    ...","preventionTips":["Source branch labels from the migration files, not hardcoded strings.","Centralize label constants to avoid typos.","Validate labels against the script directory before use."],"tags":["branch-label","revision-resolution","alembic"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}