Skip to content

feat(api-v3): add a pre_delete hook to the asset and organization deletes - #17147

Merged
Maffooch merged 1 commit into
DefectDojo:devfrom
Maffooch:fix/v3-pre-delete-hook
Dec 4, 2026
Merged

Maffooch merged 1 commit into
DefectDojo:devfrom
Maffooch:fix/v3-pre-delete-hook

Conversation

@Maffooch

@Maffooch Maffooch commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Description

Adds an optional pre_delete hook to the API v3 asset and organization delete routes, the same way the assets router already takes on_write.

build_assets_router(pre_delete=...) and build_organizations_router(pre_delete=...) call the hook with the row and the request after the 404 and 403 checks pass, and before the delete runs or is queued for the async cascade (ASYNC_OBJECT_DELETE). A distribution that mounts these routers can refuse a delete by raising from the hook, and its registered exception handler renders the response. The default is None, so open source behavior does not change: no extra query and no change in responses.

Test results

unittests/api_v3/test_apiv3_pre_delete_hook.py (new, 10 tests, both routers):

  • the hook is called once with the row (still present) and the request, then the delete runs (204)
  • a hook that raises stops the delete: the row stays and the async delete is not queued
  • the hook is not reached for a row the caller cannot see (404) or cannot delete (403)
  • with no hook the delete runs as before

The tests call the router views directly, so they need neither the v3 mount nor a fixture, and they run on both V3_FEATURE_LOCATIONS legs. Ruff check and format are clean on the changed files.

Documentation

No user-facing change: this is an extension point for code that builds the routers.

Checklist

  • Make sure to rebase your PR against the very latest dev.
  • Submit all PRs, features and bug fixes alike, against the dev branch.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Your code is Ruff compliant (see ruff.toml).
  • Your code is python 3.13 compliant.
  • Model changes must include the necessary migrations in the dojo/db_migrations folder. (none)
  • Add applicable tests to the unit tests.

🤖 Generated with Claude Code

…etes

build_assets_router and build_organizations_router take an optional
pre_delete callable, called with the row and the request once the 404 and
403 checks pass and before the delete is run or queued for the async
cascade. A downstream distribution can refuse a delete there by raising,
the same way on_write lets it persist its own columns. The default is None,
so open source behaves exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Maffooch
Maffooch requested a review from blakeaowens as a code owner December 3, 2026 17:25
@Maffooch Maffooch added this to the 3.6.0 milestone Dec 3, 2026
@Maffooch
Maffooch added this pull request to the merge queue Dec 4, 2026
Merged via the queue into DefectDojo:dev with commit 8486d2a Dec 4, 2026
64 of 67 checks passed
@Maffooch
Maffooch deleted the fix/v3-pre-delete-hook branch December 4, 2026 01:22
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.

3 participants