Fix error in sql reporter upgrade

A recent change added extra columns to the buildset table.  The
end time of the last job is guaranteed to be at least the start time
of the first job.  However, if there are queue items in-flight
during the upgrade, those buildsets will not have th first job
timestamps initialized.  This produces the following traceback:

Exception in pipeline processing:
  Traceback (most recent call last):
    File "/usr/local/lib/python3.8/site-packages/zuul/scheduler.py", line 1977, in _process_pipeline
      while not self._stopped and pipeline.manager.processQueue():
    File "/usr/local/lib/python3.8/site-packages/zuul/manager/__init__.py", line 1563, in processQueue
      item_changed, nnfi = self._processOneItem(
    File "/usr/local/lib/python3.8/site-packages/zuul/manager/__init__.py", line 1498, in _processOneItem
      self.reportItem(item)
    File "/usr/local/lib/python3.8/site-packages/zuul/manager/__init__.py", line 1793, in reportItem
      reported=not self._reportItem(item))
    File "/usr/local/lib/python3.8/site-packages/zuul/manager/__init__.py", line 1925, in _reportItem
      self.sql.reportBuildsetEnd(item.current_build_set, action, final=True)
    File "/usr/local/lib/python3.8/site-packages/zuul/driver/sql/sqlreporter.py", line 91, in reportBuildsetEnd
      if build.end_time and build.end_time > end_time:
  TypeError: '>' not supported between instances of 'datetime.datetime' and 'NoneType'

This change protects against that error; if the first build start
time is None, then we won't perform the comparison and the last
build end time will also be None.

Change-Id: I78840dc58cd950ba85b0dcf108fc0a659b051e95
This commit is contained in:
James E. Blair 2022-02-25 16:42:19 -08:00
parent 6571a8336a
commit 7b93424cc8
1 changed files with 2 additions and 1 deletions

View File

@ -88,7 +88,8 @@ class SQLReporter(BaseReporter):
db_buildset.message = message
end_time = db_buildset.first_build_start_time
for build in db_buildset.builds:
if build.end_time and build.end_time > end_time:
if (build.end_time and end_time
and build.end_time > end_time):
end_time = build.end_time
db_buildset.last_build_end_time = end_time
elif buildset.builds: