{"id":"111cf7fde37236d3","repo":"sqlalchemy/alembic","slug":"dependency-resolution-failed-broken-map","errorCode":null,"errorMessage":"Dependency resolution failed; broken map","messagePattern":"Dependency resolution failed; broken map","errorType":"exception","errorClass":"RevisionError","httpStatus":null,"severity":"error","filePath":"alembic/script/revision.py","lineNumber":900,"sourceCode":"            target = is_revision(target_for)\n            todo.append(target)\n            if check:\n                per_target = set()\n\n            while todo:\n                rev = todo.pop()\n                if check:\n                    per_target.add(rev)\n\n                if rev in seen:\n                    continue\n                seen.add(rev)\n                # Check for map errors before collecting.\n                for rev_id in fn(rev):\n                    next_rev = map_[rev_id]\n                    assert next_rev is not None\n                    if next_rev.revision != rev_id:\n                        raise RevisionError(\n                            \"Dependency resolution failed; broken map\"\n                        )\n                    todo.append(next_rev)\n                yield rev\n            if check:\n                overlaps = per_target.intersection(targets).difference(\n                    [target]\n                )\n                if overlaps:\n                    raise RevisionError(\n                        \"Requested revision %s overlaps with \"\n                        \"other requested revisions %s\"\n                        % (\n                            target.revision,\n                            \", \".join(r.revision for r in overlaps),\n                        )\n                    )\n","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/script/revision.py#L882-L918","documentation":"Raised inside _iterate_related_revisions when a dependency pointer in the map resolves to a Revision object whose own .revision attribute disagrees with the key it was looked up by. This is an internal integrity check indicating the revision map is corrupted/inconsistent (e.g., two ids aliasing one object). It is a RevisionError and should not normally be reachable by user input.","triggerScenarios":"Corrupted or hand-built revision map where map_[rev_id].revision != rev_id; bugs in add_revision / _add_depends_on that mis-index a Revision; monkeypatching of Revision.revision after insertion.","commonSituations":"Test fixtures that build a map by hand and reuse the same Revision object under multiple keys; plugin code that mutates Revision.revision in place; very rare alembic internal bugs.","solutions":["Report as a bug to alembic if produced with stock scripts and unmodified Revision objects.","Audit any custom code that constructs or mutates Revision objects / the revision map directly.","Rebuild the map from scratch via the script directory generator instead of mutating it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from alembic.script.revision import RevisionError\ntry:\n    list(rev_map.iterate_revisions(upper, lower))\nexcept RevisionError as e:\n    if 'broken map' in str(e):\n        # rebuild the map from the script directory; report as bug\n        ...","preventionTips":["Do not construct or mutate Revision objects or the revision map by hand.","Rebuild maps from the script directory generator.","Treat this error as a corruption/bug signal and file upstream if reproducible."],"tags":["revision-map","integrity","internal","alembic"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}