Skip to content

bug: recurring git-sync fails entirely when a git branch maps to an already-merged (read-only) Infrahub branch #9931

Description

@minitriga

Component

Git Integration

Infrahub version

Not specified by reporter (observed via the recurring git_repositories_sync flow; traceback below).

Current Behavior

The recurring git_repositories_sync flow records each branch's commit through update_commit_valueCoreRepositoryUpdate. When a git branch still present on the remote (here description-field) maps to an Infrahub branch that has already been merged (and is therefore read-only), the mutation is rejected:

Branch 'description-field' has been merged and is read-only. No modifications are allowed.

The resulting GraphQLError is not among the exceptions collect_pending_imports isolates per branch (RepositoryError, CommitNotFoundError, GitCommandError, ValueError), and none of the enclosing frames catch it either (sync_git_repo_with_origin_and_tag_on_failure and sync_repository_from_origin catch only RepositoryError/CommitNotFoundError; sync_remote_repositories has no per-repo guard). So a single merged-but-undeleted git branch:

  • aborts collection for all other branches of the same repository that cycle, and
  • propagates unhandled to the top of the flow, aborting the entire flow run — every repository iterated after the failing one is skipped that cycle.

Because this is the per-minute cron and the git branch persists until deleted, the failure recurs every cycle: git-sync is effectively frozen for the affected repository (and all later-ordered repositories) until the branch is removed from the remote.

Expected Behavior

A git branch that maps to a merged/read-only Infrahub branch should not break the recurring sync. Either the sync skips recording commits for merged/read-only branches, or the read-only-branch rejection is isolated per branch (like the other per-branch failures) so the remaining branches and repositories still sync.

Steps to Reproduce

  1. Register a read-write CoreRepository and let it sync.
  2. Create a working branch (e.g. description-field) that exists both on the git remote and as an Infrahub branch.
  3. Merge that Infrahub branch (it becomes read-only) without deleting the corresponding branch on the git remote.
  4. Let the per-minute git_repositories_sync flow run.
  5. The flow fails with the GraphQLError above; sync for that repository (and any repository iterated after it) no longer progresses.

Additional Information

Traceback
infrahub_sdk.exceptions.GraphQLError: An error occurred while executing the GraphQL Query
 mutation ($repository_id: String!, $commit: String!) {
   CoreRepositoryUpdate(data: { id: $repository_id, commit: { is_protected: true, source: $repository_id, value: $commit } }) {
     ok
     object { commit { value } }
   }
 }
, [{'message': "Branch 'description-field' has been merged and is read-only. No modifications are allowed.",
   'locations': [{'line': 3, 'column': 9}], 'path': ['CoreRepositoryUpdate'],
   'extensions': {'code': 'UNDEFINED_ERROR', 'http_status': 400, 'data': {}}}]

  File ".../infrahub/git/tasks.py", sync_remote_repositories
  File ".../infrahub/git/tasks.py", sync_repository_from_origin
  File ".../infrahub/git/tasks.py", sync_git_repo_with_origin_and_tag_on_failure
  File ".../infrahub/git/sync.py", RepositorySyncer.sync -> collect_pending_imports
  File ".../infrahub/git/repository.py", collect_pending_imports -> update_commit_value
  File ".../infrahub/git/base.py", update_commit_value -> sdk.repository_update_commit

(Reporter's traceback line numbers correspond to an earlier release; the code path is unchanged on the current stable line: collect_pending_imports in backend/infrahub/git/repository.py calls update_commit_value, and the GraphQLError it raises falls outside the isolated exception tuple.)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    group/backendIssue related to the backend (API Server, Git Agent)type/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions