Skip to content

Commit

Permalink
Merge pull request #3712 from obynio/brid-patch
Browse files Browse the repository at this point in the history
Fix getBuildRequests results when using multiple sourcestamps
  • Loading branch information
tardyp committed Nov 24, 2017
2 parents 294ed3a + e518da0 commit 52335d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions master/buildbot/db/buildrequests.py
Expand Up @@ -83,6 +83,10 @@ def thd(conn):

def getBuildRequests(self, builderid=None, complete=None, claimed=None,
bsid=None, branch=None, repository=None, resultSpec=None):

def deduplicateBrdict(brdicts):
return list(({b['buildrequestid']: b for b in brdicts}).values())

def thd(conn):
reqs_tbl = self.db.model.buildrequests
claims_tbl = self.db.model.buildrequest_claims
Expand Down Expand Up @@ -116,14 +120,13 @@ def thd(conn):
q = q.where(sstamps_tbl.c.repository == repository)

if resultSpec is not None:
return resultSpec.thd_execute(
return deduplicateBrdict(resultSpec.thd_execute(
conn, q,
lambda r: self._brdictFromRow(r, self.db.master.masterid))
lambda r: self._brdictFromRow(r, self.db.master.masterid)))

res = conn.execute(q)

return [self._brdictFromRow(row, self.db.master.masterid)
for row in res.fetchall()]
return deduplicateBrdict([self._brdictFromRow(row, self.db.master.masterid) for row in res.fetchall()])
return self.db.pool.do(thd)

def claimBuildRequests(self, brids, claimed_at=None, _reactor=reactor):
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/newsfragments/duplicate-brid.bugfix
@@ -0,0 +1 @@
Fix duplicate build requests results in :py:class:`~buildbot.db.buildrequests.BuildRequestsConnectorComponent` when querying the database (:issue:`3712`).
5 changes: 5 additions & 0 deletions master/buildbot/test/unit/test_db_buildrequests.py
Expand Up @@ -319,6 +319,11 @@ def do_test_getBuildRequests_branch_arg(self, **kwargs):
branch='branch_A', repository='repository_A'),
fakedb.BuildsetSourceStamp(buildsetid=self.BSID + 3,
sourcestampid=self.BSID + 3),
# multiple sourcestamps on the same buildset are possible
fakedb.SourceStamp(id=self.BSID + 4,
branch='branch_B', repository='repository_B'),
fakedb.BuildsetSourceStamp(buildsetid=self.BSID + 3,
sourcestampid=self.BSID + 4),
])
d.addCallback(lambda _:
self.db.buildrequests.getBuildRequests(**kwargs))
Expand Down

0 comments on commit 52335d3

Please sign in to comment.