From e9e08fec3c2a64a74e7171b4a8ee5f989f1d8733 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 1 Oct 2019 13:12:13 +0200 Subject: [PATCH] [IMP] forwardport: fix creation of FP PR in some testing cases When running tests on some machines, it's apparently possible for the PR-creation webhook to come back before the PR creation request has, leading to the creation of the PR from the API call duplicating that of the webhook and blowing up. To fix, immediately commit the transaction then check if we already have the PR we just created in the system, and only create it explicitly if not. --- forwardport/models/project.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/forwardport/models/project.py b/forwardport/models/project.py index 85af0503..24a8e15b 100644 --- a/forwardport/models/project.py +++ b/forwardport/models/project.py @@ -486,8 +486,18 @@ class PullRequests(models.Model): } ) assert 200 <= r.status_code < 300, r.json() - new_pr = self._from_gh(r.json()) - _logger.info("Created forward-port PR %s", new_pr) + r = r.json() + self.env.cr.commit() + + new_pr = self.search([ + ('number', '=', r['number']), + ('repository.name', '=', r['base']['repo']['full_name']), + ], limit=1) + if new_pr: + _logger.info("Received forward-port PR %s", new_pr) + else: + new_pr = self._from_gh(r) + _logger.info("Created forward-port PR %s", new_pr) new_batch |= new_pr new_pr.write({