Skip to content

Commit

Permalink
Use sqlalchemy 2.0 query syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Nov 14, 2023
1 parent db9d5b5 commit a0055ca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ def set_state(self, state: JobState) -> bool:
# generate statement that will not revert DELETING or DELETED back to anything non-terminal
rval = session.execute(
update(Job.table)
.where(Job.table.c.id == self.id, ~Job.table.c.state.in_((Job.states.DELETING, Job.states.DELETED)))
.where(Job.id == self.id, ~Job.state.in_((Job.states.DELETING, Job.states.DELETED)))
.values(state=state)
)
if rval.rowcount == 1:
Expand Down Expand Up @@ -8226,25 +8226,26 @@ def cancel(self):

def cancel_invocation_steps(self):
sa_session = object_session(self)
assert sa_session
job_subq = (
sa_session.query(Job.id)
select(Job.id)
.join(WorkflowInvocationStep)
.filter(WorkflowInvocationStep.workflow_invocation_id == self.id)
.filter(~Job.table.c.state.in_(Job.finished_states))
.filter(~Job.state.in_(Job.finished_states))
.with_for_update()
.scalar_subquery()
)
sa_session.execute(update(Job.table).where(Job.id == job_subq).values({"state": Job.states.DELETING}))

job_collection_subq = (
sa_session.query(Job.id)
select(Job.id)
.join(ImplicitCollectionJobsJobAssociation)
.join(ImplicitCollectionJobs)
.join(
WorkflowInvocationStep, WorkflowInvocationStep.implicit_collection_jobs_id == ImplicitCollectionJobs.id
)
.filter(WorkflowInvocationStep.workflow_invocation_id == self.id)
.filter(~Job.table.c.state.in_(Job.finished_states))
.filter(~Job.state.in_(Job.finished_states))
.with_for_update()
.subquery()
)
Expand Down

0 comments on commit a0055ca

Please sign in to comment.