Skip to content

fix(tests): prevent tag inheritance tests from polluting dev Celery queue#14493

Merged
valentijnscholten merged 1 commit intoDefectDojo:bugfixfrom
valentijnscholten:fix-tags-test-celery-queue-pollution
Mar 12, 2026
Merged

fix(tests): prevent tag inheritance tests from polluting dev Celery queue#14493
valentijnscholten merged 1 commit intoDefectDojo:bugfixfrom
valentijnscholten:fix-tags-test-celery-queue-pollution

Conversation

@valentijnscholten
Copy link
Copy Markdown
Member

@valentijnscholten valentijnscholten commented Mar 11, 2026

Summary

When you are running DD locally in dev mode and run the test_tags unit test, it will dispatch a celery task via propagate_tags_on_product(4). In dev mode this means the celery worker will pick it up and apply it to product 4 in the local DD (non-test) database. In my case this was a product with 10002 findings from the JFrog Unified unit test sample file. If you have tag inheritance enabled, this task will run for hours on end updating each finding with the inherited tags.
This PR ensures all celery tasks are executed synchronously in test_tags.py so that it gets executed in the test database.

  • 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 (observed: 84–88 minute runs over ~10,000 JFrog Xray Unified findings)
  • Fix: add @override_settings(CELERY_TASK_ALWAYS_EAGER=True) to the three test classes that enable system-wide product tag inheritance (InheritedTagsTests, InheritedTagsImportTestAPI, InheritedTagsImportTestUI). This makes Celery run tasks inline in the test process, keeping tasks off the shared Redis queue and ensuring assertions see the results of tag propagation before checking them

…elery queue

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.
@Maffooch Maffooch requested review from blakeaowens and dogboat March 11, 2026 21:16
Copy link
Copy Markdown
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@valentijnscholten valentijnscholten changed the title fix(tests): prevent tag inheritance tests from polluting production Celery queue fix(tests): prevent tag inheritance tests from polluting dev Celery queue Mar 11, 2026
@valentijnscholten valentijnscholten merged commit b339824 into DefectDojo:bugfix Mar 12, 2026
544 of 546 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants