From 87c08ff42172c9fe7735777c98d07ec32c4cd179 Mon Sep 17 00:00:00 2001 From: Vasudeo Nimbekar Date: Tue, 29 Nov 2022 18:16:56 +0530 Subject: [PATCH] Update get execution's tasks functionality After this patch, it will validate execution-id exists in the DB while fetching tasks for the execution-id So, GET /v2/executions/execution_id/tasks API will return 404 for absent execution id. Closes-Bug: #1998210 Change-Id: I6ac05f4b87c470a68cd67f19d1bd95a4d6cebe59 --- mistral/api/controllers/v2/task.py | 7 +++++++ mistral/tests/unit/api/v2/test_executions.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/mistral/api/controllers/v2/task.py b/mistral/api/controllers/v2/task.py index 7c9e4ea50..518bde5bf 100644 --- a/mistral/api/controllers/v2/task.py +++ b/mistral/api/controllers/v2/task.py @@ -28,6 +28,7 @@ from mistral.api.controllers.v2 import sub_execution from mistral.api.controllers.v2 import types from mistral import context from mistral.db.v2 import api as db_api +from mistral.db.v2.sqlalchemy import models as db_models from mistral import exceptions as exc from mistral import expressions as expr from mistral.lang import parser as spec_parser @@ -440,6 +441,12 @@ class ExecutionTasksController(rest.RestController): """ acl.enforce('tasks:list', context.ctx()) + with db_api.transaction(): + db_api.get_workflow_execution( + workflow_execution_id, + fields=(db_models.WorkflowExecution.id,) + ) + filters = filter_utils.create_filters_from_request_params( workflow_execution_id=workflow_execution_id, created_at=created_at, diff --git a/mistral/tests/unit/api/v2/test_executions.py b/mistral/tests/unit/api/v2/test_executions.py index a3b1b787f..7873b1f33 100644 --- a/mistral/tests/unit/api/v2/test_executions.py +++ b/mistral/tests/unit/api/v2/test_executions.py @@ -994,3 +994,17 @@ class TestExecutionsController(base.APITest): "The field 'id' can't hold None value.", resp.body.decode() ) + + @mock.patch.object(db_api, 'get_workflow_execution', MOCK_NOT_FOUND) + def test_get_all_tasks_within_execution(self): + fake_execution_id = "00000000-0000-0000-0000-000000000000" + resp = self.app.get( + '/v2/executions/%s/tasks' % fake_execution_id, + expect_errors=True + ) + + self.assertEqual(404, resp.status_int) + self.assertIn( + "Object not found", + resp.body.decode() + )