Unverified Commit d812248e authored by Marius van den Beek's avatar Marius van den Beek Committed by GitHub
Browse files

Merge pull request #20784 from mvdbeek/ensure_invocation_state_not_none

[25.0] Ensure that workflow invocations are persisted with state
parents 15e56169 b5add075
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -9000,6 +9000,10 @@ class WorkflowInvocation(Base, UsesCreateAndUpdateTime, Dictifiable, Serializabl
    states = InvocationState
    non_terminal_states = [states.NEW, states.READY]

    def __strict_check_before_flush__(self):
        if self.state is None:
            raise Exception("Workflow invocation without state, this should not happen")

    def get_last_workflow_invocation_step_update_time(self) -> Optional[datetime]:
        session = required_object_session(self)
        stmt = select(func.max(WorkflowInvocationStep.update_time)).where(
@@ -9331,7 +9335,8 @@ class WorkflowInvocation(Base, UsesCreateAndUpdateTime, Dictifiable, Serializabl
    def to_dict(self, view="collection", value_mapper=None, step_details=False, legacy_job_state=False):
        rval = super().to_dict(view=view, value_mapper=value_mapper)
        if rval["state"] is None:
            # bugs could result in no state being set
            # this shouldn't happen anymore, likely fixed in https://github.com/galaxyproject/galaxy/pull/20784
            log.warning(f"Encountered workflow invocation [{self.id}] with no state set")
            rval["state"] = self.states.FAILED
        if view == "element":
            steps = []
+1 −0
Original line number Diff line number Diff line
@@ -523,6 +523,7 @@ def workflow_run_config_to_request(
    workflow_invocation = WorkflowInvocation()
    workflow_invocation.uuid = uuid.uuid1()
    workflow_invocation.history = run_config.target_history
    workflow_invocation.state = WorkflowInvocation.states.NEW
    ensure_object_added_to_session(workflow_invocation, object_in_session=run_config.target_history)

    def add_parameter(name: str, value: str, type: WorkflowRequestInputParameter.types) -> None:
+7 −1
Original line number Diff line number Diff line
@@ -173,7 +173,13 @@ class WorkflowSchedulingManager(ConfiguresHandlers):
        if exception:
            raise exception

    def queue(self, workflow_invocation, request_params, flush=True, initial_state: Optional[InvocationState] = None):
    def queue(
        self,
        workflow_invocation: model.WorkflowInvocation,
        request_params,
        flush: bool = True,
        initial_state: Optional[InvocationState] = None,
    ):
        initial_state = initial_state or model.WorkflowInvocation.states.NEW
        workflow_invocation.set_state(initial_state)
        workflow_invocation.scheduler = request_params.get("scheduler", None) or self.default_scheduler_id