fix: defer fetch request when repo is not yet initialized during GitProvider init - #70102
Open
waterWang wants to merge 1 commit into
Open
fix: defer fetch request when repo is not yet initialized during GitProvider init#70102waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #70081
Summary
During
GitProvider.__init__(),fetch_request_check()is called (line 531) before the provider subclass has had a chance to callinit_remote(). If afetch_requestfile happens to exist in the salt working dir at this point (e.g. left over from a prior run), the code path:immediately accesses
self.repo.remotes[0](Pygit2_fetch, and GitPython_fetchboth do this). Butself.repois only set later, insideinit_remote(), which the subclasses call aftersuper().__init__()returns. The result is an intermittentAttributeError: 'Pygit2' object has no attribute 'repo'(or'GitPython') that makes git_pillar/gitfs highstates fail every few runs.Fix
In
fetch_request_check(), checkgetattr(self, "repo", None). If the repo is not yet initialized, returnFalsewithout removing the fetch_request file — the file is preserved so the next call tofetch_request_check()(fromcheckout(), by which timeself.repoexists) processes it.Pygit2andGitPythonproviders.GitCLIis unaffected (its_fetch()shells out to the git binary and never touchesself.repo).Tests
tests/pytests/functional/utils/gitfs/test_gitfs.pytests/pytests/functional/utils/gitfs/test_pillar.py