From a5794a1a24261206c168adf72202613d8c5c9c27 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 1 Oct 2019 09:57:35 +0200 Subject: [PATCH] [FIX] forwardport: better version of previous fix Turns out we don't want to close the cursor on success, we just want to commit, but that's not what the default context manager does. So don't use said context manager. --- runbot_merge/models/pull_requests.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/runbot_merge/models/pull_requests.py b/runbot_merge/models/pull_requests.py index 808733a7..51dee79f 100644 --- a/runbot_merge/models/pull_requests.py +++ b/runbot_merge/models/pull_requests.py @@ -1264,19 +1264,21 @@ class Commit(models.Model): # chances are low that we'll have more than one commit for c in self.search([('to_check', '=', True)]): try: - with self.env.cr: - c.to_check = False - st = json.loads(c.statuses) - pr = PRs.search([('head', '=', c.sha)]) - if pr: - pr._validate(st) - # heads is a json-encoded mapping of reponame:head, so chances - # are if a sha matches a heads it's matching one of the shas - stagings = Stagings.search([('heads', 'ilike', c.sha)]) - if stagings: - stagings._validate() + c.to_check = False + st = json.loads(c.statuses) + pr = PRs.search([('head', '=', c.sha)]) + if pr: + pr._validate(st) + # heads is a json-encoded mapping of reponame:head, so chances + # are if a sha matches a heads it's matching one of the shas + stagings = Stagings.search([('heads', 'ilike', c.sha)]) + if stagings: + stagings._validate() except Exception: _logger.exception("Failed to apply commit %s (%s)", c, c.sha) + self.env.cr.rollback() + else: + self.env.cr.commit() _sql_constraints = [ ('unique_sha', 'unique (sha)', 'no duplicated commit'),