[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.
This commit is contained in:
Xavier Morel 2019-10-01 09:57:35 +02:00
parent eb9eeb670a
commit a5794a1a24

View File

@ -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'),