From edd70e1625c4087847b070beadbbebc1c8392f74 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Mon, 28 Aug 2023 16:20:05 -0600 Subject: [PATCH] Commit job state change before running update hooks Without this, the state queried by `job_storage` will not match the updated state. This can cause a problem if a hook tries to restart a canceled job because `job_storage` will still see the state as `CANCELING`. Fixes: #11169 --- kolibri/core/tasks/storage.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kolibri/core/tasks/storage.py b/kolibri/core/tasks/storage.py index 000d99069cb..016bdfa858c 100644 --- a/kolibri/core/tasks/storage.py +++ b/kolibri/core/tasks/storage.py @@ -577,6 +577,10 @@ def _update_job( self._update_job_fields(job, **kwargs) orm_job.saved_job = job.to_json() session.add(orm_job) + try: + session.commit() + except Exception as e: + logger.error("Got an error running session.commit(): {}".format(e)) for hook in self._hooks: hook.update( job,