From 980415375c372e6f32086ce55078e8e5533f456b Mon Sep 17 00:00:00 2001 From: Donny Peeters <46660228+Donnype@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:16:58 +0200 Subject: [PATCH] Hotfix for normalizer API bug (#3475) Signed-off-by: Donny Peeters --- mula/scheduler/server/handlers/tasks.py | 17 +++++++++++------ mula/tests/integration/test_api.py | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mula/scheduler/server/handlers/tasks.py b/mula/scheduler/server/handlers/tasks.py index db3391dc2d6..6912e7023ab 100644 --- a/mula/scheduler/server/handlers/tasks.py +++ b/mula/scheduler/server/handlers/tasks.py @@ -139,12 +139,16 @@ def list( ] } elif task_type == "normalizer": - f_plugin = storage.filters.Filter( - column="data", - field="normalizer__id", - operator="eq", - value=plugin_id, - ) + f_plugin = { + "and": [ + storage.filters.Filter( + column="data", + field="normalizer__id", + operator="eq", + value=plugin_id, + ) + ] + } else: f_plugin = { "or": [ @@ -182,6 +186,7 @@ def list( detail=f"invalid filter(s) [exception: {exc}]", ) from exc except storage.errors.StorageError as exc: + self.logger.exception(exc) raise fastapi.HTTPException( status_code=fastapi.status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"error occurred while accessing the database [exception: {exc}]", diff --git a/mula/tests/integration/test_api.py b/mula/tests/integration/test_api.py index 0511c200f52..9f6440c5801 100644 --- a/mula/tests/integration/test_api.py +++ b/mula/tests/integration/test_api.py @@ -706,6 +706,13 @@ def test_get_tasks_min_created_at_future(self): self.assertEqual(200, response.status_code) self.assertEqual(0, len(response.json()["results"])) + def test_get_normalizer_filtered(self): + # This used to be a bug where the normalizer filter was missing a nesting on the operator + params = {"task_type": "normalizer", "plugin_id": "kat_nmap_normalize"} + response = self.client.get("/tasks", params=params) + self.assertEqual(200, response.status_code) + self.assertEqual(0, len(response.json()["results"])) + def test_get_tasks_filtered(self): response = self.client.post( "/tasks",