From ee6f3570f66cd5f1f5cf70c297e6eb7670aa838f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Wed, 23 Aug 2023 09:30:09 +0200 Subject: [PATCH 1/2] hub: do not call save twice in Task.save() ... to ensure that the db operation is atomic. Fixes: c5d7f8e68a24df08a5425206ae686c34f0ebf135 ("Fix calculating the number of task's subtasks in new Django versions") Related: https://github.com/release-engineering/kobo/pull/217#discussion_r1300849327 --- kobo/hub/models.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kobo/hub/models.py b/kobo/hub/models.py index da29766f..c410b937 100644 --- a/kobo/hub/models.py +++ b/kobo/hub/models.py @@ -606,9 +606,8 @@ def __str__(self): return u"#%s [method: %s, state: %s, worker: %s]" % (self.id, self.method, self.get_state_display(), self.worker) def save(self, *args, **kwargs): - # save to db to precalculate subtask counts and obtain an ID (on insert) for stdout and traceback - super(self.__class__, self).save() - self.subtask_count = self.subtasks().count() + if self.id is not None: + self.subtask_count = self.subtasks().count() super(self.__class__, self).save() self.logs.save() if self.parent: From da941ba59656c72e4282e6b8b2a4e90941335e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Thu, 24 Aug 2023 08:04:04 +0200 Subject: [PATCH 2/2] hub: decorate Task.save with transaction.atomic ... to ensure that the task and its parent are updated atomically. --- kobo/hub/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kobo/hub/models.py b/kobo/hub/models.py index c410b937..456b602c 100644 --- a/kobo/hub/models.py +++ b/kobo/hub/models.py @@ -605,6 +605,7 @@ def __str__(self): return u"#%s [method: %s, state: %s, worker: %s, parent: #%s]" % (self.id, self.method, self.get_state_display(), self.worker, self.parent.id) return u"#%s [method: %s, state: %s, worker: %s]" % (self.id, self.method, self.get_state_display(), self.worker) + @transaction.atomic def save(self, *args, **kwargs): if self.id is not None: self.subtask_count = self.subtasks().count()