Fix KeyError: 'sortKey'
The data returned by the gerrit query are in the line format:
<json for change 1>
<json for change 2>
...
<json for change N>
<json of query stats>
<blank line>
The current [:-1] dropped the blank line, and previously the Gerrit
trigger would then drop the query stats with a [:-1]. That has
since been removed. However, it needs to be dropped before the
simpleQuery processor performs the sortKey lookup.
Instead, drop any lines which don't include 'sortKey', which means
they aren't valid data lines (they are either stats lines, the blank,
or some other cruft).
Change-Id: I2b8ffdc70af436b34e7cee431ec4820c6e2d91c3
diff --git a/zuul/lib/gerrit.py b/zuul/lib/gerrit.py
index 799459d..5aad953 100644
--- a/zuul/lib/gerrit.py
+++ b/zuul/lib/gerrit.py
@@ -156,7 +156,8 @@
lines = out.split('\n')
if not lines:
return False
- data = [json.loads(line) for line in lines[:-1]]
+ data = [json.loads(line) for line in lines
+ if "sortKey" in line]
if not data:
return False
self.log.debug("Received data from Gerrit query: \n%s" %