ENG-2784: Auto-populate rules and targets on DSR policy creation#7494
Merged
ENG-2784: Auto-populate rules and targets on DSR policy creation#7494
Conversation
Add support for auto-generating rules and default data-category targets when creating DSR policies via PATCH /api/v1/dsr/policy. Accepts either `action_type` (auto-generates rule + default targets) or explicit `rules` with inline `targets` — mutually exclusive. Existing policies being updated ignore both fields (backward compatible). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…orted types - Override action_type with exclude=True in PolicyResponse so it doesn't leak into the API response schema - Add early validation against SUPPORTED_ACTION_TYPES before attempting rule creation, giving a clear error for unsupported types like "update" - Add test for unsupported action_type and assertion that action_type is excluded from response Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add type: ignore comments for PolicyResponse field overrides and Policy.create_or_update return type (FidesBase -> Policy) - Apply ruff formatting to test file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Greptile SummaryThis PR successfully implements auto-population of rules and targets when creating DSR policies, with two mutually exclusive input options: Key changes:
Implementation quality:
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 95bf52e |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
vcruces
approved these changes
Feb 27, 2026
Contributor
vcruces
left a comment
There was a problem hiding this comment.
Looks great to me! The code is easy to follow and the key cases are well covered by tests
| pol = Policy.filter( | ||
| db=db, conditions=(Policy.key == policy_resp["key"]) | ||
| ).first() | ||
| pol.delete(db=db) |
Contributor
There was a problem hiding this comment.
Are these explicit deletes necessary? Don’t these instances get cleaned up automatically after each test?
Contributor
Author
There was a problem hiding this comment.
Good call! Thanks :) - removing.
JadeCara
commented
Feb 27, 2026
JadeCara
commented
Feb 27, 2026
JadeCara
commented
Feb 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket ENG-2784
Description Of Changes
Add support for auto-generating rules and default data-category targets when creating DSR policies via
PATCH /api/v1/dsr/policy.The policy creation endpoint now accepts two new optional fields (mutually exclusive):
action_type— auto-generates a rule (named{policy_name} Rule) and seeds default data-category targets:user.*2nd-level categories excludinguser.financial,user.payment,user.authorization(same defaults that ship OOTB)rules— creates explicitly provided rules with optional inlinetargets, using the existingRuleCreateschema extended with atargetsfieldBackward compatible: if neither field is provided, behavior is unchanged. Existing policies being updated ignore both fields.
Code Changes
src/fides/api/schemas/policy.py- AddedRuleCreateWithTargetsschema, addedaction_typeandrulesfields toPolicyschema with mutual exclusivity validatorsrc/fides/api/api/v1/endpoints/policy_endpoints.py- Added_create_rule_and_targets()and_auto_create_rule_and_targets()helpers; modifiedcreate_or_update_policiesto auto-create rules/targets for new policiestests/ops/api/v1/endpoints/test_policy_endpoints.py- AddedTestCreatePolicyWithAutoPopulatedRulesclass with 7 parametrized/standalone testsSteps to Confirm
Create an access policy with auto-population:
Verify: response includes a rule named "My Access Policy Rule" with default
user.*targetsCreate an erasure policy:
Verify: rule has
masking_strategy.strategy == "hmac"and default targetsCreate a consent policy:
Same pattern with
"action_type": "consent"— verify rule created with no targetsCreate a policy with explicit rules and targets:
Verify: rule and target created as specified
Verify mutual exclusivity: passing both
action_typeandrulesreturns 422Pre-Merge Checklist
CHANGELOG.mdupdated