Skip to content

celery.backend_cleanup got an unexpected keyword argument 'async_user' #14555

@pablosnt

Description

@pablosnt

Bug description
We are getting the following exception when the scheduled celery.backend_cleanup's task is processed:

ERROR [celery.beat:284] Message Error: Couldn't apply scheduled task celery.backend_cleanup: backend_cleanup() got an unexpected keyword argument 'async_user'
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/celery/beat.py", line 404, in apply_async
	return task.apply_async(entry_args, entry_kwargs,
		   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/dojo/celery.py", line 74, in apply_async
	return super().apply_async(args=args, kwargs=kwargs, **options)
		   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/celery/app/task.py", line 573, in apply_async
	check_arguments(*(args or ()), **(kwargs or {}))
TypeError: backend_cleanup() got an unexpected keyword argument 'async_user'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/celery/beat.py", line 282, in apply_entry
	result = self.apply_async(entry, producer=producer, advance=False)
			 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/celery/beat.py", line 412, in apply_async
	reraise(SchedulingError, SchedulingError(
File "/usr/local/lib/python3.12/site-packages/celery/exceptions.py", line 109, in reraise
	raise value.with_traceback(tb)
File "/usr/local/lib/python3.12/site-packages/celery/beat.py", line 404, in apply_async
	return task.apply_async(entry_args, entry_kwargs,
		   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/dojo/celery.py", line 74, in apply_async
	return super().apply_async(args=args, kwargs=kwargs, **options)
		   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/celery/app/task.py", line 573, in apply_async
	check_arguments(*(args or ()), **(kwargs or {}))
celery.beat.SchedulingError: Couldn't apply scheduled task celery.backend_cleanup: backend_cleanup() got an unexpected keyword argument 'async_user'

As far as I know, the celery.backend_cleanup is a default celery task that is executed daily at 04:00 AM to remove expired tasks results.

Reviewing the code, the reason of the issue seems to be the inclusion of the async_user parameter to all the DefectDojo async tasks here, which is executed too for default celery tasks like celery.backend_cleanup

Steps to reproduce
Steps to reproduce the behavior:

  1. Deploy DefectDojo
  2. Access the celerybeat pod
  3. Run python3 manage.py shell
  4. Run the following Python code to trigger the celery.backend_cleanup asynchronously
from dojo.celery import app
app.tasks['celery.backend_cleanup'].apply_async()

Result:

Image

Alternative:

  1. Check the 04:00 AM logs

Expected behavior
The celery.backend_cleanup task is executed successfully.

Deployment method (select with an X)

  • Docker Compose
  • Kubernetes
  • GoDojo

Environment information

  • Operating System: MacOS Tahoe 26.2
  • Docker Compose version 5.1.0
  • DefectDojo version (see footer) or commit message: 2.56.2

Additional context (optional)
I will open a pull request to contribute the fix soon

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions