From d5804dce7d674e54dbd37cc6cace2e8cbae8f991 Mon Sep 17 00:00:00 2001 From: Dale Cannon Date: Tue, 26 Nov 2024 11:11:51 +0000 Subject: [PATCH 1/3] Save Workflow instance in forward op to fix migration application --- tasks/migrations/0012_taskworkflow_assign_summary_task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/migrations/0012_taskworkflow_assign_summary_task.py b/tasks/migrations/0012_taskworkflow_assign_summary_task.py index 38f0dda86..26e22ed3b 100644 --- a/tasks/migrations/0012_taskworkflow_assign_summary_task.py +++ b/tasks/migrations/0012_taskworkflow_assign_summary_task.py @@ -12,7 +12,7 @@ def assign_new_summary_task_on_workflow(apps, schema_editor): title="Workflow summarising task", description="Workflow summarising task.", ) - TaskWorkflow.save() + task_workflow.save() class Migration(migrations.Migration): From 981fa4138c256351a16801a3250e190b52591465 Mon Sep 17 00:00:00 2001 From: Dale Cannon Date: Tue, 26 Nov 2024 11:44:38 +0000 Subject: [PATCH 2/3] Have TaskWorkflowTemplate.create_task_workflow() create summary task from data param --- tasks/models/workflow.py | 14 +++++++++----- tasks/tests/test_workflow_models.py | 15 +++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tasks/models/workflow.py b/tasks/models/workflow.py index 35f149252..0ff7e3c6f 100644 --- a/tasks/models/workflow.py +++ b/tasks/models/workflow.py @@ -91,13 +91,17 @@ def get_task_templates(self) -> models.QuerySet: ) @atomic - def create_task_workflow(self) -> "TaskWorkflow": - """Create a workflow and it subtasks, using values from this template - workflow and its task templates.""" + def create_task_workflow(self, summary_data: dict) -> "TaskWorkflow": + """ + Create a workflow and it subtasks, using values from this template + workflow and its task templates. + The `summary_data` param is used to populate the details of the `TaskWorkflow.summary_task` instance. + """ + + summary_task = Task.objects.create(**summary_data) task_workflow = TaskWorkflow.objects.create( - title=self.title, - description=self.description, + summary_task=summary_task, creator_template=self, ) diff --git a/tasks/tests/test_workflow_models.py b/tasks/tests/test_workflow_models.py index 270e7b055..d80d646cc 100644 --- a/tasks/tests/test_workflow_models.py +++ b/tasks/tests/test_workflow_models.py @@ -13,8 +13,14 @@ def test_create_task_workflow_from_task_workflow_template( ): """Test creation of TaskWorkflow instances from TaskWorkflowTemplates using its `create_task_workflow()` method.""" + summary_data = { + "title": "Workflow title", + "description": "Workflow description", + } task_workflow = ( - task_workflow_template_three_task_template_items.create_task_workflow() + task_workflow_template_three_task_template_items.create_task_workflow( + summary_data, + ) ) # Test that workflow values are valid. @@ -22,11 +28,8 @@ def test_create_task_workflow_from_task_workflow_template( task_workflow.creator_template == task_workflow_template_three_task_template_items ) - assert task_workflow.title == task_workflow_template_three_task_template_items.title - assert ( - task_workflow.description - == task_workflow_template_three_task_template_items.description - ) + assert task_workflow.summary_task.title == summary_data["title"] + assert task_workflow.summary_task.description == summary_data["description"] assert task_workflow.get_items().count() == 3 # Validate that item positions are equivalent. From f056afc6d0ff1798b38402c96f8497172e08f862 Mon Sep 17 00:00:00 2001 From: Dale Cannon Date: Thu, 28 Nov 2024 12:26:15 +0000 Subject: [PATCH 3/3] Make explicit create_task_workflow() params --- tasks/models/workflow.py | 12 ++++-------- tasks/tests/test_workflow_models.py | 13 ++++++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tasks/models/workflow.py b/tasks/models/workflow.py index 0ff7e3c6f..26a00c931 100644 --- a/tasks/models/workflow.py +++ b/tasks/models/workflow.py @@ -91,15 +91,11 @@ def get_task_templates(self) -> models.QuerySet: ) @atomic - def create_task_workflow(self, summary_data: dict) -> "TaskWorkflow": - """ - Create a workflow and it subtasks, using values from this template - workflow and its task templates. + def create_task_workflow(self, title: str, description: str) -> "TaskWorkflow": + """Create a workflow and it subtasks, using values from this template + workflow and its task templates.""" - The `summary_data` param is used to populate the details of the `TaskWorkflow.summary_task` instance. - """ - - summary_task = Task.objects.create(**summary_data) + summary_task = Task.objects.create(title=title, description=description) task_workflow = TaskWorkflow.objects.create( summary_task=summary_task, creator_template=self, diff --git a/tasks/tests/test_workflow_models.py b/tasks/tests/test_workflow_models.py index d80d646cc..93cda5eed 100644 --- a/tasks/tests/test_workflow_models.py +++ b/tasks/tests/test_workflow_models.py @@ -13,13 +13,12 @@ def test_create_task_workflow_from_task_workflow_template( ): """Test creation of TaskWorkflow instances from TaskWorkflowTemplates using its `create_task_workflow()` method.""" - summary_data = { - "title": "Workflow title", - "description": "Workflow description", - } + title = "Workflow title" + description = "Workflow description" task_workflow = ( task_workflow_template_three_task_template_items.create_task_workflow( - summary_data, + title=title, + description=description, ) ) @@ -28,8 +27,8 @@ def test_create_task_workflow_from_task_workflow_template( task_workflow.creator_template == task_workflow_template_three_task_template_items ) - assert task_workflow.summary_task.title == summary_data["title"] - assert task_workflow.summary_task.description == summary_data["description"] + assert task_workflow.summary_task.title == title + assert task_workflow.summary_task.description == description assert task_workflow.get_items().count() == 3 # Validate that item positions are equivalent.