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
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):
ivantodorovich
force-pushed
the
19.0-fix-queue_job-cancel-dependent-date
branch
from
October 22, 2026 13:38
61d0bd3 to
6063e7d
Compare
- Cancelling a job now cancels its dependents all the way down. Before, only direct dependents were cancelled: in A -> B -> C, cancelling A left C waiting forever. Test: test_button_cancel_dependencies_cascade - A job is cancelled as soon as one of its dependencies is cancelled. Before, it was only cancelled when all of them were, so a job with one cancelled and one done (or running) dependency waited forever. Tests: test_button_cancel_dependencies_other_parent_done, test_button_done_dependencies_other_parent_cancelled - Cancelled dependents get a date_cancelled, the same as the cancelled job. It was left empty, so the autovacuum never removed them. Tests: test_button_cancel_dependencies, test_button_cancel_dependencies_cascade - Cancelled dependents get a result telling why they were cancelled. Tests: test_button_cancel_dependencies_cascade, test_button_cancel_dependencies_selected - Cancelling a job along with its dependent cancels the dependent once. Before, it was cancelled a second time as part of the selection, overwriting its date and result. Test: test_button_cancel_dependencies_selected _get_common_dependent_jobs_query is replaced by the dependency_ids and dependent_ids computed fields on queue.job, used to enqueue and cancel dependent jobs through the ORM.
ivantodorovich
force-pushed
the
19.0-fix-queue_job-cancel-dependent-date
branch
from
October 22, 2026 13:53
6063e7d to
f073767
Compare
Contributor
Author
|
Hi @florentx I digged a bit deeper and found other issues with the current implementation, all described in the PR description and covered by new unit tests. So I decided to refactor and use the orm and computed fields instead of this query. |
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.
wait_dependenciesforever.Test:
test_button_cancel_dependencies_cascadeTests:
test_button_cancel_dependencies_other_parent_done,test_button_done_dependencies_other_parent_cancelleddate_cancelled, the same as the cancelled job. It was left empty, so the autovacuum never removed them.Tests:
test_button_cancel_dependencies,test_button_cancel_dependencies_cascaderesulttelling why they were cancelled.Tests:
test_button_cancel_dependencies_cascade,test_button_cancel_dependencies_selectedTest:
test_button_cancel_dependencies_selected_get_common_dependent_jobs_queryis replaced by thedependency_ids/dependent_idscomputed fields onqueue.job, used to enqueue and cancel dependent jobs through the ORM.