From a0a07c234ba8faec30b2b072783d70ce6b94bae0 Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Wed, 11 Mar 2026 20:22:18 +0100 Subject: [PATCH] fix(tests): prevent tag inheritance tests from polluting production Celery queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit product_tags_post_add_remove dispatches propagate_tags_on_product via dojo_dispatch_task. When the signal fires outside a request context (e.g. during test setUp), get_current_user() returns None, so we_want_async() always returns True regardless of block_execution — the task goes to the shared Redis queue. The real Celery worker then picks it up and runs against the live database, causing multi-hour tag propagation runs over large products. Fix: add @override_settings(CELERY_TASK_ALWAYS_EAGER=True) to the three test classes that enable system-wide product tag inheritance. This makes Celery run tasks inline in the test process, keeping tasks off the shared Redis queue and ensuring assertions see propagated tags. --- unittests/test_tags.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unittests/test_tags.py b/unittests/test_tags.py index 54ef2a21df7..f29ea69f6ae 100644 --- a/unittests/test_tags.py +++ b/unittests/test_tags.py @@ -4,7 +4,7 @@ from django.conf import settings from django.contrib.auth.models import User -from django.test import Client +from django.test import Client, override_settings from django.urls import reverse from dojo.models import Finding, Product, Test @@ -454,6 +454,7 @@ def reimport_scan_with_params(self, test_id, filename, scan_type="ZAP Scan", min return {"test": new_test_id} +@override_settings(CELERY_TASK_ALWAYS_EAGER=True) @versioned_fixtures class InheritedTagsTests(DojoAPITestCase): @@ -610,6 +611,7 @@ def test_remove_tag_from_product_then_add_tag_to_product(self): self.assertEqual(product_tags_post_addition, self._convert_instance_tags_to_list(objects.get("finding"))) +@override_settings(CELERY_TASK_ALWAYS_EAGER=True) @versioned_fixtures class InheritedTagsImportTestAPI(DojoAPITestCase, InheritedTagsImportMixin): @@ -626,6 +628,7 @@ def setUp(self): InheritedTagsImportMixin.setUp(self) +@override_settings(CELERY_TASK_ALWAYS_EAGER=True) @versioned_fixtures class InheritedTagsImportTestUI(DojoAPITestCase, InheritedTagsImportMixin):