Skip to content

Propagate async_user via crum.impersonate in DojoAsyncTask base class#14308

Open
valentijnscholten wants to merge 3 commits intoDefectDojo:bugfixfrom
valentijnscholten:fix/async-user-crum-impersonate
Open

Propagate async_user via crum.impersonate in DojoAsyncTask base class#14308
valentijnscholten wants to merge 3 commits intoDefectDojo:bugfixfrom
valentijnscholten:fix/async-user-crum-impersonate

Conversation

@valentijnscholten
Copy link
Member

@valentijnscholten valentijnscholten commented Feb 12, 2026

Summary

  • DojoAsyncTask.__call__ pops async_user from kwargs and wraps task execution in crum.impersonate(user), so get_current_user() returns the correct user transparently in all Celery workers.
  • Fixes user context being lost in nested task dispatches (sub-tasks from workers had no HTTP request, causing block_execution to be silently ignored).
  • When a task is called directly (not via apply_async), the existing crum context is preserved.
  • Removes manual async_user extraction from consumers: we_want_async(), add_findings_to_auto_group(), do_false_positive_history().

@valentijnscholten valentijnscholten added this to the 2.55.3 milestone Feb 12, 2026
@valentijnscholten valentijnscholten added the affects_pro PRs that affect Pro and need a coordinated release/merge moment. label Feb 12, 2026
Previously, async_user was passed through kwargs and each consumer had
to manually extract it. This was fragile and caused user context to be
lost in nested Celery task dispatches (e.g. sub-tasks spawned from
within a worker had no HTTP request context, so get_current_user()
returned None and block_execution was silently ignored).

DojoAsyncTask.__call__ now pops async_user from kwargs and wraps the
task execution in crum.impersonate(user), making get_current_user()
return the correct user transparently for all downstream code.

When a task is called directly (not via apply_async), async_user is
absent from kwargs. In that case the existing crum context is preserved
so that callers who set a user via impersonate() are not disrupted.

Consumer-side cleanup:
- we_want_async() uses get_current_user() directly
- add_findings_to_auto_group() drops async_user fallback
- do_false_positive_history() drops async_user pop from kwargs
- Delete task docstrings updated
@valentijnscholten valentijnscholten force-pushed the fix/async-user-crum-impersonate branch from a419cfa to dc6df06 Compare February 12, 2026 19:14
Add blank lines before class docstrings (D203) and move method
docstring summary to second line (D213) to satisfy upstream Ruff config.
dojo_dispatch_task was popping sync from kwargs before running the
task, preventing tasks from knowing they should run their own
sub-tasks synchronously. Remove the pop so sync flows through to
task functions. Add explicit sync parameter to
post_process_findings_batch and forward it to calculate_grade so
product grading also runs inline when the caller requests sync
execution.
@Maffooch Maffooch marked this pull request as ready for review February 13, 2026 19:31
Copy link
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

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

Manually tested this one, and everything looks good! Not sure what AccesLint is on tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects_pro PRs that affect Pro and need a coordinated release/merge moment. unittests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants