fix(schema): backport repository cascade delete to stable (closes #9934)
Why
Backport of #9832 to stable.
On stable, renaming or removing a git-sourced check definition (or transform, generator, or GraphQL query) freezes repository import: the reconcile tries to delete the stale object, but a historical CoreUserValidator still pins it through the mandatory check_definition relationship, so the delete is rejected and the entire import aborts (sync_status: error-import). The repository stays stuck on the old commit and every subsequent sync fails identically. This is #9934.
The root cause is that the repository-managed ownership relationships were never wired with on_delete=CASCADE. #9832 fixed that on develop; this PR backports it so the reconcile delete cascades to the pinning validator and succeeds, letting the import complete.
Non-goals: no integrator-level workaround (the superseded approach in #9937 caught the error and left the stale object behind, which reviewers correctly flagged as too general and prone to silent inconsistency).
What changed
- The repository ownership tree is wired with
on_delete=CASCADE(transformations,queries,checks,generators), with the missing parent-side relationships added so the cascade reaches every managed leaf, includingCheckDefinition → UserValidator. - Deleting a repository-managed object now cascades to the historical validators/artifacts/instances that pin it, instead of the delete being rejected. As a result, removing a check definition during git-sync no longer aborts the import.
- Added an integration test proving the git-sync import path: a check definition pinned by a
CoreUserValidatoris removed from config, the import deletes it, the cascade removes the validator, and the import completes.
Implementation notes: this is a faithful backport of #9832. The schema definitions are cherry-picked as-is; protocols.py, schema.graphql, and the frontend GraphQL types were regenerated on stable (not diff-merged from develop). stable already carries the deep delete-validator engine, so no on_delete logic change was needed — only the wiring.
What stayed the same: no graph migration required (update_core_schema reconciles the on_delete values and new relationships during upgrade); GRAPH_VERSION unchanged.
Accepted trade-off
As in #9832: deleting a repository (or a check/generator/artifact definition directly) now also deletes validators attached to proposed changes and their generated artifacts/instances. This is the intended ownership semantics and lands on stable with this backport.
How to review
backend/infrahub/core/schema/definitions/core/*.py— theon_delete=CASCADEwiring and new parent-side relationships (the actual fix).- Generated files (
protocols.py,schema.graphql, frontend GraphQL types) are mechanical regenerations. - Tests:
test_delete_validator.pyandtest_node_manager_delete.pyare from #9832;test_git_repository.py::TestInfrahubClient::test_import_deletes_check_definition_pinned_by_validatoris the added git-sync regression for #9934.
How to test
cd backend
uv run pytest tests/unit/core/node/test_delete_validator.py
uv run pytest tests/integration/git/test_git_repository.py::TestInfrahubClient::test_import_deletes_check_definition_pinned_by_validator -x
Impact & rollout
- Backward compatibility: delete semantics change per the accepted trade-off above; no API contract change.
- Config/env changes: none.
- Deployment notes: no graph migration; safe to deploy.
Checklist
- Tests added/updated
- Changelog entry added
- External docs updated — N/A
- Internal .md docs updated — N/A
- I have reviewed AI generated content
Summary by cubic
Backports cascade delete for repository-owned objects to stable so git imports don’t freeze when a removed definition is still referenced. Deletes now cascade to validators, instances, and artifacts, allowing imports to advance to the new commit. Closes #9934.
- Bug Fixes
- Wired cascade from repositories to their managed objects and dependents, adding missing parent-side relationships (e.g., CheckDefinition → UserValidator, ArtifactDefinition → Artifact/Validator, GeneratorDefinition → Instance/Validator, Transformation → ArtifactDefinition, GraphQLQuery → Group).
- Git import no longer aborts when a removed check definition is pinned by a validator; reconcile delete succeeds and the repository sync completes.
- Regenerated
protocols.py,schema.graphql, and frontend GraphQL types; added unit coverage for cascade resolution and a git-sync regression test verifying the fix.