Skip to content

fix: defer fetch request when repo is not yet initialized during GitProvider init - #70102

Open
waterWang wants to merge 1 commit into
saltstack:masterfrom
waterWang:fix-fetch-request-init-order
Open

fix: defer fetch request when repo is not yet initialized during GitProvider init#70102
waterWang wants to merge 1 commit into
saltstack:masterfrom
waterWang:fix-fetch-request-init-order

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #70081

Summary

During GitProvider.__init__(), fetch_request_check() is called (line 531) before the provider subclass has had a chance to call init_remote(). If a fetch_request file happens to exist in the salt working dir at this point (e.g. left over from a prior run), the code path:

fetch_request_check() -> self.fetch() -> self._fetch()

immediately accesses self.repo.remotes[0] (Pygit2 _fetch, and GitPython _fetch both do this). But self.repo is only set later, inside init_remote(), which the subclasses call after super().__init__() returns. The result is an intermittent AttributeError: 'Pygit2' object has no attribute 'repo' (or 'GitPython') that makes git_pillar/gitfs highstates fail every few runs.

Fix

In fetch_request_check(), check getattr(self, "repo", None). If the repo is not yet initialized, return False without removing the fetch_request file — the file is preserved so the next call to fetch_request_check() (from checkout(), by which time self.repo exists) processes it.

  • Applies to both Pygit2 and GitPython providers.
  • GitCLI is unaffected (its _fetch() shells out to the git binary and never touches self.repo).

Tests

  • tests/pytests/functional/utils/gitfs/test_gitfs.py
  • tests/pytests/functional/utils/gitfs/test_pillar.py

During GitProvider.__init__(), fetch_request_check() is called before
the provider subclass has had a chance to call init_remote(). If a
fetch_request file happens to exist at this point, the code path
[fetch_request_check -> fetch -> _fetch] accesses self.repo.remotes,
but self.repo has not been set yet, causing an AttributeError.

Fixes saltstack#70081

Add a guard in fetch_request_check(): if self.repo is None (repo
not yet initialized), return False without removing the fetch request
file. The file will be processed by the next call to fetch_request_check
from checkout(), by which time self.repo will be available.

Affects both Pygit2 and GitPython providers. GitCLI is unaffected
since its _fetch() uses subprocess and does not access self.repo.
@waterWang
waterWang requested a review from a team as a code owner August 20, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Intermittent ext_pillar failure: 'Pygit2' object has no attribute 'repo'

1 participant