{"record":{"id":"1cd059b6e7069ada","repo":"pytorch/pytorch","slug":"schema-version-downgraded-from-commit-base-schem","errorCode":null,"errorMessage":"Schema version downgraded from {commit.base['SCHEMA_VERSION']} to {commit.result['SCHEMA_VERSION']}.","messagePattern":"Schema version downgraded from (.+?) to (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/export/update_schema.py","lineNumber":35,"sourceCode":"        help=\"Print the schema instead of writing it to file.\",\n    )\n    parser.add_argument(\n        \"--force-unsafe\",\n        action=\"store_true\",\n        help=\"!!! Only use this option when you are a chad. !!! Force to write the schema even if schema validation doesn't pass.\",\n    )\n    args = parser.parse_args()\n\n    assert os.path.exists(args.prefix), (\n        f\"Assuming path {args.prefix} is the root of pytorch directory, but it doesn't exist.\"\n    )\n\n    commit = schema_check.update_schema()\n\n    abs_yaml_path = os.path.join(args.prefix, commit.yaml_path)\n    if os.path.exists(abs_yaml_path):\n        if commit.result[\"SCHEMA_VERSION\"] < commit.base[\"SCHEMA_VERSION\"]:\n            raise RuntimeError(\n                f\"Schema version downgraded from {commit.base['SCHEMA_VERSION']} to {commit.result['SCHEMA_VERSION']}.\"\n            )\n\n        if commit.result[\"TREESPEC_VERSION\"] < commit.base[\"TREESPEC_VERSION\"]:\n            raise RuntimeError(\n                f\"Treespec version downgraded from {commit.base['TREESPEC_VERSION']} to {commit.result['TREESPEC_VERSION']}.\"\n            )\n    else:\n        assert args.force_unsafe, (\n            f\"Existing schema yaml file not found in {abs_yaml_path}, please check if you provided correct prefix path, or use --force-unsafe to try again.\"\n        )\n\n    next_version, reason = schema_check.check(commit, args.force_unsafe)\n\n    if next_version is not None and next_version != commit.result[\"SCHEMA_VERSION\"]:\n        raise RuntimeError(\n            f\"Schema version is not updated from {commit.base['SCHEMA_VERSION']} to {next_version}.\\n\"\n            + \"Please either:\\n\"","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/pytorch/pytorch/blob/dcd2ecae775af66439b7ede4e7a82540b058c59c/scripts/export/update_schema.py#L17-L53","documentation":"Raised by scripts/export/update_schema.py after regenerating the export flatbuffer schema YAML when the newly computed SCHEMA_VERSION is lower than the version recorded in the existing schema.yaml. Version numbers are monotonically increasing; a downgrade means schema.py changes made older serialized artifacts unreadable or the wrong baseline file was compared, so the script refuses to overwrite the YAML.","triggerScenarios":"Running python scripts/export/update_schema.py --prefix <pytorch root> when the checked-out schema.yaml has a higher SCHEMA_VERSION than what the current torch/_export or serialization code produces — e.g. after checking out an older commit of schema.py while keeping a newer generated schema.yaml, or after a partial revert of a version bump.","commonSituations":"Rebasing or switching branches and having a stale generated schema.yaml. Reverting a PR that bumped SCHEMA_VERSION without regenerating from the reverted state. Mixing files from different commits after a conflict resolution.","solutions":["Check out the schema.yaml (and schema.py) from the same commit so base and result are consistent, then re-run","If the downgrade is intentional (true revert of a schema change), re-run with --force-unsafe to accept the downgrade","Verify with git log/diff on the schema files which commit bumped the version and align your tree to it"],"exampleFix":"# before\ngit checkout old-schema-pr -- torch/_export/serde/schema.py\npython scripts/export/update_schema.py --prefix .\n# after\ngit checkout main -- torch/_export/serde/schema.py torch/_export/serde/schema.yaml\npython scripts/export/update_schema.py --prefix .  # or add --force-unsafe for a true revert","handlingStrategy":"validation","validationCode":"import yaml\n\ndef versions(path: str) -> dict:\n    return yaml.safe_load(open(path))\n\nbase = versions(\"torch/_export/serde/schema.yaml\")\nassert result[\"SCHEMA_VERSION\"] >= base.get(\"SCHEMA_VERSION\", 0), \"schema version would downgrade\"","typeGuard":null,"tryCatchPattern":"try:\n    subprocess.run([sys.executable, \"scripts/export/update_schema.py\", \"--prefix\", \".\"], check=True)\nexcept subprocess.CalledProcessError as e:\n    if \"downgraded\" in (e.stdout or \"\"):\n        # realign schema.py/schema.yaml to one commit, or pass --force-unsafe deliberately\n        raise\n    raise","preventionTips":["Keep generated schema.yaml and its source schema.py from the same commit; regenerate after any schema.py change","When reverting a version-bump PR, use --force-unsafe consciously and note it in the PR"],"tags":["export","serialization","schema","versioning","runtimeerror"],"backgroundTag":null,"analyzedSha":"dcd2ecae775af66439b7ede4e7a82540b058c59c","analyzedAt":"2026-08-14T19:21:26.615Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}