Skip to content

Commit a426d61

Browse files
committed
Clarify the select_for_update logic of cfbot_ingest
1 parent bd49a2c commit a426d61

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pgcommitfest/commitfest/views.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,12 @@ def cfbot_ingest(message):
830830
# not it doesn't contain the newest patches that the CFBot knows about.
831831
return
832832

833-
old_branch = CfbotBranch.objects.select_for_update().filter(patch_id=patch_id).first()
833+
# We don't simply fetch this from the patch.cfbot_branch, because we want
834+
# to get it as select_for_update. That way we can use this row as a lock to
835+
# ensure only one cfbot HTTP request can change a patch its Branch and
836+
# Tasks at the same time. (see also transaction.atomic at the top of this
837+
# function)
838+
old_branch = CfbotBranch.objects.select_for_update().get(pk=patch_id)
834839
if old_branch and old_branch.branch_id != branch_id and old_branch.created.replace(tzinfo=timezone.utc) > created:
835840
# This is a message for an old branch, ignore it.
836841
return

0 commit comments

Comments
 (0)