fix: handle org: principal remapping failure in restriction_policies [DRALLSTSBX-49]#540
Merged
michael-richey merged 3 commits intomainfrom Apr 22, 2026
Merged
Conversation
…[DRALLSTSBX-49]
When GET /api/v1/org returns 403, the pre_apply_hook was crashing with
UnboundLocalError then falling through to an invalid .format() call,
leaving org_principal as the unformatted "org:{}" template which caused
"not a valid principal" errors on 7 dashboard restriction policies.
- Change org_principal default to None (was "org:{}")
- Move f-string assignment inside try block, replacing .format() outside try
- Add `if self.org_principal` guard in pre_resource_action_hook
- Fix split(":") to split(":", 1) in connect_id for crash safety
- Add unit tests covering all four org principal scenarios
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
3 tasks
Switch from GET /api/v1/org (requires org_management permission, returns public_id) to GET /api/v2/current_user (accessible to all users, returns org UUID matching the format used in restriction policy org: principals). Per Datadog API docs, org: principals use the UUID from current_user, not the public_id from the v1 org endpoint. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
heyronhay
approved these changes
Apr 22, 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.
Summary
UnboundLocalErrorcrash inpre_apply_hookwhenGET /api/v1/orgreturns 403org_principaldefault from"org:{}"toNoneand moves f-string assignment inside the try blockif self.org_principalguard inpre_resource_action_hookso staleorg:source-uuidprincipals are no longer overwritten with the invalid"org:{}"templatesplit(":")→split(":", 1)inconnect_idfor crash safety on unexpected principal formatsTest plan
python -m pytest tests/unit/test_restriction_policies.py -v— 4 new tests passpython -m pytest tests/unit/ -v— 326 tests passtox -e ruff,black(tox-testing pyenv) — cleanRelated
🤖 Generated with Claude Code