diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 513362112795..707187296652 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1691,15 +1691,15 @@ def set_state(self, state: JobState) -> bool: return False session = object_session(self) if session and self.id and state not in Job.finished_states: - # generate statement that will not revert DELETING or DELETED back to anything non-terminal + # Do not update if job is in a terminal state rval = session.execute( update(Job.table) - .where(Job.id == self.id, ~Job.state.in_((Job.states.DELETING, Job.states.DELETED))) + .where(Job.id == self.id, ~Job.state.in_((state, *Job.finished_states))) .values(state=state) ) + with transaction(session): + session.commit() if rval.rowcount == 1: - # Need to expire state since we just updated it, but ORM doesn't know about it. - session.expire(self, ["state"]) self.state_history.append(JobStateHistory(self)) return True else: