From a9809ec2d2a447ed60899dd27286786797c543d7 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Thu, 20 Aug 2026 11:42:14 +0800 Subject: [PATCH] fix: defer fetch request when repo is not yet initialized 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 #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. --- salt/utils/gitfs.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/salt/utils/gitfs.py b/salt/utils/gitfs.py index e3e23d00b981..46cec6bda4d5 100644 --- a/salt/utils/gitfs.py +++ b/salt/utils/gitfs.py @@ -1350,6 +1350,19 @@ def get_url(self): def fetch_request_check(self): fetch_request = salt.utils.path.join(self._salt_working_dir, "fetch_request") if os.path.isfile(fetch_request): + if getattr(self, "repo", None) is None: + # The repo has not yet been initialized (e.g. we are being + # called from GitProvider.__init__ before the provider's + # init_remote() has run). Leave the fetch request in place + # so that a later call to this method (e.g. from checkout()) + # can honor it once self.repo exists. + log.debug( + "Fetch request present for %s remote '%s', but repo is " + "not yet initialized; deferring", + self.role, + self.id, + ) + return False log.debug("Fetch request: %s", self._salt_working_dir) try: os.remove(fetch_request)