Skip to content

[19.0] [FIX] queue_job: set date_cancelled on cancelled dependent jobs - #1015

Open
ivantodorovich wants to merge 1 commit into
OCA:19.0from
camptocamp:19.0-fix-queue_job-cancel-dependent-date
Open

ivantodorovich wants to merge 1 commit into
OCA:19.0from
camptocamp:19.0-fix-queue_job-cancel-dependent-date

Conversation

@ivantodorovich

Copy link
Copy Markdown
Contributor

cancel_dependent_jobs only updated the state, leaving date_cancelled empty, so these jobs were never removed by the autovacuum.

cancel_dependent_jobs only updated the state, leaving date_cancelled
empty, so these jobs were never removed by the autovacuum.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @sbidoul, @guewen,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:19.0 mod:queue_job Module queue_job mod:test_queue_job Module test_queue_job labels Oct 20, 2026

@florentx florentx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use same date_cancelled as parent job, and do it a little bit differently:

--- a/queue_job/job.py
+++ b/queue_job/job.py
@@ -545,10 +545,10 @@ class Job:
             finally:
                 self._env = env
 
-    def _get_common_dependent_jobs_query(self):
-        return """
+    def _get_common_dependent_jobs_query(self, sql_set_clause):
+        return f"""
             UPDATE queue_job
-            SET state = %s
+            SET {sql_set_clause}
             FROM (
             SELECT child.id, array_agg(parent.state) as parent_states
             FROM queue_job job
@@ -579,13 +579,15 @@ class Job:
         return any(self.__reverse_depends_on_uuids)
 
     def enqueue_waiting(self):
-        sql = self._get_common_dependent_jobs_query()
+        sql = self._get_common_dependent_jobs_query("state = %s")
         self.env.cr.execute(sql, (PENDING, self.uuid, DONE, WAIT_DEPENDENCIES))
         self.env["queue.job"].invalidate_model(["state"])
 
     def cancel_dependent_jobs(self):
-        sql = self._get_common_dependent_jobs_query()
-        self.env.cr.execute(sql, (CANCELLED, self.uuid, CANCELLED, WAIT_DEPENDENCIES))
+        assert self.state == CANCELLED, "Job is not cancelled"
+        sql = self._get_common_dependent_jobs_query("state = %s, date_cancelled = %s")
+        sql_args = (CANCELLED, self.date_cancelled, self.uuid, CANCELLED, WAIT_DEPENDENCIES)
+        self.env.cr.execute(sql, sql_args)
         self.env["queue.job"].invalidate_model(["state"])
 
     def store(self):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:queue_job Module queue_job mod:test_queue_job Module test_queue_job series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants