{"record":{"id":"7ed10cef8634a59f","repo":"sqlalchemy/alembic","slug":"path-is-not-in-the-same-subtree-as-other","errorCode":null,"errorMessage":"{path} is not in the same subtree as {other}","messagePattern":"(.+?) is not in the same subtree as (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"alembic/util/compat.py","lineNumber":88,"sourceCode":"    ) -> Path:\n        \"\"\"\n        Calculate the relative path of 'path' with respect to 'other',\n        optionally allowing 'path' to be outside the subtree of 'other'.\n\n        OK I used AI for this, sorry\n\n        \"\"\"\n        try:\n            return path.relative_to(other)\n        except ValueError:\n            if walk_up:\n                other_ancestors = list(other.parents) + [other]\n                for ancestor in other_ancestors:\n                    try:\n                        return path.relative_to(ancestor)\n                    except ValueError:\n                        continue\n                raise ValueError(\n                    f\"{path} is not in the same subtree as {other}\"\n                )\n            else:\n                raise\n\n\ndef importlib_metadata_get(group: str) -> Sequence[EntryPoint]:\n    \"\"\"provide a facade for metadata.entry_points().\n\n    This is no longer a \"compat\" function as of Python 3.10, however\n    the function is widely referenced in the test suite and elsewhere so is\n    still in this module for compatibility reasons.\n\n    \"\"\"\n    return metadata.entry_points().select(group=group)\n\n\ndef formatannotation_fwdref(","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/5551b5d35f985c99cb8f1af2b3c526b050e4c059/alembic/util/compat.py#L70-L106","documentation":"Raised by path_relative_to (the Python <3.12 fallback in alembic/util/compat.py:88) when walk_up=True and the given path is not relative to any ancestor of 'other'. This means the two paths share no common subtree — they live on entirely different filesystem roots or diverge at the root level. The function walks up through other.parents attempting a match and fails.","triggerScenarios":"Calling compat.path_relative_to(path, other, walk_up=True) where path and other have no common ancestor (compat.py:82-90). In production this is called from command.py:91-103 during 'alembic init' to compute the script_location relative to the config file — fails if the migrations directory and config file are on different drives (Windows) or mount points.","commonSituations":"On Windows, placing alembic.ini on C: and the migrations directory on D:. Symlinks that resolve to different roots. Running 'alembic init' with a directory path that is not under the config file's parent tree. Unusual mount layouts in containers where /config and /migrations are separate roots.","solutions":["Ensure the migrations directory and the config file (alembic.ini or pyproject.toml) are on the same filesystem root.","Use an absolute path for script_location in the config file to bypass relative path computation.","On Windows, verify both paths are on the same drive letter.","Move the config file or migrations directory so one is within the other's subtree."],"exampleFix":"# before (alembic.ini on C:, migrations on D:)\nalembic init D:\\migrations\n\n# after\n# keep config and migrations on the same drive\nalembic init C:\\project\\migrations","handlingStrategy":"validation","validationCode":"import os\n\ndef paths_share_root(path1, path2):\n    p1 = os.path.abspath(path1)\n    p2 = os.path.abspath(path2)\n    return os.path.commonpath([p1, p2]) not in ('', '/') or os.path.splitdrive(p1)[0] == os.path.splitdrive(p2)[0]","typeGuard":null,"tryCatchPattern":"from alembic.util.exc import CommandError\n\ntry:\n    command.init(config, directory)\nexcept CommandError as e:\n    if \"not in the same subtree\" in str(e):\n        # use absolute path for script_location instead\n        print(\"Use absolute path or move config and migrations to same root\")\n    raise","preventionTips":["Keep alembic.ini/pyproject.toml and the migrations directory on the same filesystem root.","On Windows, ensure config and migrations are on the same drive.","Use absolute paths for script_location in config to avoid relative path computation."],"tags":["alembic","path-handling","filesystem","compatibility","windows"],"backgroundTag":null,"analyzedSha":"5551b5d35f985c99cb8f1af2b3c526b050e4c059","analyzedAt":"2026-08-11T01:38:46.612Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}