Skip to content

ENG-2755: Add DELETE /dsr/policy/{policy_key} endpoint with in-use guard#7459

Merged
JadeCara merged 5 commits intomainfrom
ENG-2755-delete-policy-endpoint
Feb 24, 2026
Merged

ENG-2755: Add DELETE /dsr/policy/{policy_key} endpoint with in-use guard#7459
JadeCara merged 5 commits intomainfrom
ENG-2755-delete-policy-endpoint

Conversation

@JadeCara
Copy link
Contributor

@JadeCara JadeCara commented Feb 23, 2026

Ticket ENG-2755

Description Of Changes

Add a DELETE /api/v1/dsr/policy/{policy_key} endpoint that allows users to remove DSR policies they no longer need. The endpoint guards against deleting policies that are actively referenced by privacy requests — returning a 409 Conflict in that case to prevent orphaned records. Child Rule and RuleTarget records are cascade-deleted via the existing Policy.delete() method.

Code Changes

  • src/fides/api/api/v1/endpoints/policy_endpoints.py - Add delete_policy DELETE handler with 404/409/204 responses, secured by POLICY_DELETE scope
  • tests/ops/api/v1/endpoints/test_policy_endpoints.py - Add TestDeletePolicy class with 5 tests covering auth, not found, in-use conflict, and successful cascade deletion

Steps to Confirm

  1. Create a test policy via PATCH /api/v1/dsr/policy with a rule and target
  2. DELETE /api/v1/dsr/policy/{policy_key} → expect 204 No Content, verify policy, rules, and targets are removed
  3. Attempt to delete a nonexistent policy → expect 404 Not Found
  4. Create a policy and associate a privacy request with it, then attempt deletion → expect 409 Conflict
  5. Attempt deletion without POLICY_DELETE scope → expect 403 Forbidden

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • No UX review needed
  • Followup issues:
    • No followup issues
  • Database migrations:
    • No migrations
  • Documentation:

Adds a new endpoint to delete DSR policies by key. Returns 409 Conflict
if the policy is referenced by any privacy requests, preventing orphaned
records. Child rules and rule targets are cascade-deleted via the
existing Policy.delete() method.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Feb 23, 2026 11:00pm
fides-privacy-center Ignored Ignored Feb 23, 2026 11:00pm

Request Review

@JadeCara JadeCara marked this pull request as ready for review February 23, 2026 22:04
@JadeCara JadeCara requested a review from a team as a code owner February 23, 2026 22:04
@JadeCara JadeCara requested review from adamsachs and removed request for a team February 23, 2026 22:04
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Adds a DELETE /api/v1/dsr/policy/{policy_key} endpoint that removes a DSR policy and cascade-deletes its child Rule and RuleTarget records, with a 409 Conflict guard when the policy is referenced by existing privacy requests.

  • The endpoint implementation is correct: it uses the existing POLICY_DELETE scope, reuses get_policy_or_error for 404 handling, and leverages Policy.delete() which already cascade-deletes rules and targets
  • Tests provide solid coverage across auth (401/403), not-found (404), in-use conflict (409), and successful cascade deletion (204)
  • Style issues: PrivacyRequest import inside the endpoint function and test methods should be moved to the top of respective modules (no circular dependency exists). A redundant DataCategory import and unnecessary manual DB cleanup in tests should be removed

Confidence Score: 4/5

  • This PR is safe to merge with minor style cleanup; no functional or security issues found.
  • The endpoint logic is correct: proper scope authorization, 404/409 guards, and cascade deletion via the existing Policy.delete() method. Test coverage is thorough. The only issues are style-related (import placement and unnecessary manual cleanup), which don't affect correctness.
  • No files require special attention — the style issues are straightforward to fix.

Important Files Changed

Filename Overview
src/fides/api/api/v1/endpoints/policy_endpoints.py Adds DELETE handler with proper 404/409/204 responses and POLICY_DELETE scope. The in-function import of PrivacyRequest should be moved to the top of the module.
tests/ops/api/v1/endpoints/test_policy_endpoints.py Good test coverage (auth, not found, in-use conflict, cascade deletion). Has in-function imports and unnecessary manual cleanup that should be addressed.
changelog/7459.yaml Standard changelog entry for the new endpoint.

Last reviewed commit: 9301db7

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Jade Wibbels and others added 3 commits February 23, 2026 15:08
Add db.expire_all() after the DELETE API call so the test session
re-queries the database instead of returning cached objects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move PrivacyRequest import to top of policy_endpoints.py
- Move PrivacyRequest import to top of test file
- Remove redundant DataCategory import in test (already at module level)
- Remove unnecessary manual cleanup in test_delete_policy_in_use

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@JadeCara JadeCara added this pull request to the merge queue Feb 24, 2026
Merged via the queue into main with commit 77cc33f Feb 24, 2026
54 checks passed
@JadeCara JadeCara deleted the ENG-2755-delete-policy-endpoint branch February 24, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants