From e12e6db653dac52357d0466c5a73b4eebffa6959 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 11 Mar 2019 14:54:58 +0100 Subject: [PATCH] [IMP] runbot_merge: lock commit to update its status in hook A status being updated on a commit is a read/modify/update, meaning it's possible for somebody else (including a concurrent event?) to concurrently update the commit and conflict leading to the webhook blowing up, which is undesirable as it's a data loss (whereas if it blows up on the other side e.g. in the cron's commit processor the cron will just take it up next iteration). --- runbot_merge/controllers/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runbot_merge/controllers/__init__.py b/runbot_merge/controllers/__init__.py index a8a28df6..33aeb319 100644 --- a/runbot_merge/controllers/__init__.py +++ b/runbot_merge/controllers/__init__.py @@ -220,7 +220,8 @@ def handle_status(env, event): event ) Commits = env['runbot_merge.commit'] - c = Commits.search([('sha', '=', event['sha'])]) + env.cr.execute('SELECT id FROM runbot_merge_commit WHERE sha=%s FOR UPDATE', [event['sha']]) + c = Commits.browse(env.cr.fetchone()) if c: c.statuses = json.dumps({ **json.loads(c.statuses),