fix: git-sync import no longer aborts on a blocked cleanup-delete (closes #9934)
Why
When a git-sourced check definition (or transform, generator, or GraphQL query) was renamed or removed from .infrahub.yml, repository import tried to delete the stale graph node during cleanup. If that node was still pinned by a historical record — e.g. a CoreUserValidator that evaluated the check and references it through the mandatory check_definition relationship — the backend correctly rejected the delete, but the importer let that single failure abort the entire import. The repository landed in sync_status: error-import and stayed stuck on the old commit; every subsequent sync re-hit the same delete and failed identically, so the repository never advanced. The only workaround was manually deleting validator records belonging to (often already-merged) proposed changes.
Goal: a removed/renamed git-sourced object should never freeze the import. If its delete is blocked because a historical node still holds it, the import completes anyway and the commit advances.
Non-goals: not cascade-deleting or detaching the historical validator records (those belong to real proposed changes), and not introducing soft-deprecation of check definitions.
Closes #9934
What changed
- Repository import no longer aborts when a repository-managed object removed from
.infrahub.ymlcannot be deleted because a historical record still references it through a mandatory relationship. The blocked delete is logged as a warning, the object is left in place, and the rest of the import completes so the commit advances. - The same tolerance applies to every reconcile cleanup-delete: check definitions, Jinja2 transforms, GraphQL queries, generator definitions, and Python transforms.
Implementation notes: the five only_graph delete loops in InfrahubRepositoryIntegrator now route through a single helper, _delete_object_removed_from_repository, which catches the infrahub_sdk.exceptions.GraphQLError raised by a blocked delete. The catch is narrow (only GraphQLError, not bare Exception) so genuine failures still surface and fail the import.
What stayed the same: no schema changes, no GraphQL/API contract changes. The backend delete-validation that rejects the delete is unchanged — only the importer's handling of that rejection changed.
How to review
backend/infrahub/git/integrator.py— the new_delete_object_removed_from_repositoryhelper and the five call sites that replaced the rawawait …delete()calls.- The delete-rejection itself lives in
backend/infrahub/core/node/delete_validator.pyand is intentionally untouched.
How to test
cd backend
uv run pytest tests/integration/git/test_git_repository.py::TestInfrahubClient::test_import_check_definition_pinned_by_validator -x
The test creates a check definition pinned by a CoreUserValidator, drops it from the repository config, and runs import_python_check_definitions. It fails on the previous code with GraphQLError: Cannot delete CoreCheckDefinition … linked to mandatory relationship check_definition on node CoreUserValidator … and passes with this fix (the import completes and the check is left in place).
Impact & rollout
- Backward compatibility: no breaking changes; no migration steps.
- Performance: negligible (one
try/exceptper cleanup-delete). - Config/env changes: none.
- Deployment notes: safe to deploy.
Checklist
- Tests added/updated
- Changelog entry added (
uv run towncrier create ...) - External docs updated (if user-facing or ops-facing change) — N/A, internal git-sync behavior
- Internal .md docs updated — N/A, no existing knowledge doc covers reconcile-delete behavior
- I have reviewed AI generated content
Summary by cubic
Fixes import freezes when a cleanup delete is blocked by a mandatory relationship (e.g., a validator pinning a check). The importer now logs a warning, keeps the object, and completes the sync so the commit advances. Closes #9934.
- Bug Fixes
- All cleanup deletes now use
_delete_object_removed_from_repository, which catchesGraphQLError, warns, and skips the delete instead of aborting the import. - Applies to CheckDefinitions, Python/Jinja2 transforms, generators, and GraphQL queries.
- Added an integration test for a check definition pinned by a
CoreUserValidator; no schema or API changes.
- All cleanup deletes now use