Repository navigation
[19.0] [FIX] queue_job: set date_cancelled on cancelled dependent jobs - #1015
Open
ivantodorovich wants to merge 1 commit into
Open
ivantodorovich wants to merge 1 commit into
ivantodorovich wants to merge 1 commit into
Conversation
cancel_dependent_jobs only updated the state, leaving date_cancelled empty, so these jobs were never removed by the autovacuum.
Contributor
florentx
reviewed
Oct 21, 2026
florentx
left a comment
Contributor
There was a problem hiding this comment.
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):
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cancel_dependent_jobs only updated the state, leaving date_cancelled empty, so these jobs were never removed by the autovacuum.