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

Merge pull request #19335 from mvdbeek/nested_subworkflow_import_fix

[24.1] Fix importing shared workflows with deeply nested subworkflows
parents 2ca8678b 2406c879
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -7616,7 +7616,7 @@ class StoredWorkflow(Base, HasTags, Dictifiable, RepresentById, UsesCreateAndUpd
        order_by=lambda: -Workflow.id,
        cascade_backrefs=False,
    )
    latest_workflow = relationship(
    latest_workflow: Mapped["Workflow"] = relationship(
        "Workflow",
        post_update=True,
        primaryjoin=(lambda: StoredWorkflow.latest_workflow_id == Workflow.id),
@@ -7722,7 +7722,7 @@ class StoredWorkflow(Base, HasTags, Dictifiable, RepresentById, UsesCreateAndUpd
        )
        return bool(sa_session.scalar(stmt))

    def copy_tags_from(self, target_user, source_workflow):
    def copy_tags_from(self, target_user, source_workflow: "StoredWorkflow"):
        # Override to only copy owner tags.
        for src_swta in source_workflow.owner_tags:
            new_swta = src_swta.copy()
@@ -7895,7 +7895,7 @@ class Workflow(Base, Dictifiable, RepresentById):
        """
        return self.top_level_workflow.stored_workflow

    def copy(self, user=None):
    def copy(self, user: User):
        """Copy a workflow for a new StoredWorkflow object.

        Pass user if user-specific information needed.
@@ -8206,7 +8206,7 @@ class WorkflowStep(Base, RepresentById, UsesCreateAndUpdateTime):
                break
        return target_output

    def copy_to(self, copied_step, step_mapping, user=None):
    def copy_to(self, copied_step: "WorkflowStep", step_mapping: Dict[int, "WorkflowStep"], user: User):
        copied_step.order_index = self.order_index
        copied_step.type = self.type
        copied_step.tool_id = self.tool_id
@@ -8238,10 +8238,10 @@ class WorkflowStep(Base, RepresentById, UsesCreateAndUpdateTime):
                copied_step.subworkflow = subworkflow
                copied_subworkflow = subworkflow
            else:
                # Can this even happen, building a workflow with a subworkflow you don't own ?
                copied_subworkflow = subworkflow.copy()
                # Importing a shared workflow with a subworkflow step
                copied_subworkflow = subworkflow.copy(user=user)
                stored_workflow = StoredWorkflow(
                    user, name=copied_subworkflow.name, workflow=copied_subworkflow, hidden=True
                    user=user, name=copied_subworkflow.name, workflow=copied_subworkflow, hidden=True
                )
                copied_subworkflow.stored_workflow = stored_workflow
                copied_step.subworkflow = copied_subworkflow
+1 −1
Original line number Diff line number Diff line
@@ -1144,7 +1144,7 @@ class UsesStoredWorkflowMixin(SharableItemSecurityMixin, UsesAnnotations):
            except exceptions.ToolMissingException:
                pass

    def _import_shared_workflow(self, trans, stored):
    def _import_shared_workflow(self, trans, stored: model.StoredWorkflow):
        """Imports a shared workflow"""
        # Copy workflow.
        imported_stored = model.StoredWorkflow()