Add source attribute to GitConnection

Currently, the GitConnection doesn't provide a 'source' attribute. So
far this wasn't a problem as the source attribute was only accessed
within the same connection/driver.

With the ChangeCache we are now accessing the source attribute outside
of the specific connection/driver combination which fails in case of a
GitConnection with the following exception:

  Traceback (most recent call last):
    File "/workspace/zuul/zk/vendor/watchers.py", line 177, in _log_func_exception
      result = self._func(data, stat, event)
    File "/workspace/zuul/zk/change_cache.py", line 201, in _cacheItemWatcher
      self._get(key, data_uuid, zstat)
    File "/workspace/zuul/zk/change_cache.py", line 306, in _get
      change = self._changeFromData(data)
    File "/workspace/zuul/zk/change_cache.py", line 410, in _changeFromData
      project = self.connection.source.getProject(change_data["project"])
  AttributeError: 'GitConnection' object has no attribute 'source'

This seems to be only a problem in a multi scheduler setup when the
ChangeCache tries to load a change from ZooKeeper.

To fix this we simply add the source attribute to the GitConnection.
This uses the same approach like other connections by calling
driver.getSource().

Change-Id: I9503bf117f7fab31038e11eef9db65205d55e2e5
This commit is contained in:
Felix Edel 2021-11-16 12:02:55 +01:00 committed by James E. Blair
parent bb6afc55aa
commit e009ea443a
1 changed files with 1 additions and 0 deletions

View File

@ -62,6 +62,7 @@ class GitConnection(ZKChangeCacheMixin, BaseConnection):
else:
self.canonical_hostname = 'localhost'
self.projects = {}
self.source = driver.getSource(self)
def toDict(self):
d = super().toDict()