fix(scopes): return 404 instead of 500 for a missing scope policy - #935
Open
sameer-soni wants to merge 1 commit into
Open
fix(scopes): return 404 instead of 500 for a missing scope policy#935sameer-soni wants to merge 1 commit into
sameer-soni wants to merge 1 commit into
Conversation
GET /scopes/{scope_id}/policy falls back to the default scope bundle when the
requested scope is absent, and _generate_default_scope_bundle re-raised
ScopeNotFoundError when no "default" scope existed either. That exception was
uncaught, so the route returned a 500 for an unknown or not-yet-synced scope
(the OPAL client hits this on connect until the scope syncs). Return a 404
instead, matching get_scope/refresh_scope and the client's 404 handling.
Closes permitio#919
✅ Deploy Preview for opal-docs canceled.
|
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.
Fixes Issue
Closes #919
Changes proposed
GET /scopes/{scope_id}/policyfalls back to the default scope bundle when the requested scope isn't found. If nodefaultscope exists either,_generate_default_scope_bundlere-raisedScopeNotFoundError, which was never caught, so the route returned a500("Uncaught server exception") for an unknown or not-yet-synced scope. The OPAL client hits this on connect (it fetches/scopes/{scope_id}/policybefore the scope has synced), so it sees repeated 500s until the sync completes._generate_default_scope_bundlenow raisesHTTPException(404)instead ofScopeNotFoundErrorwhen neither the requested scope nor adefaultscope can be served, matching the existingget_scope/refresh_scoperoutes and the client's existing 404 handling.scope_policy_fallback_test.pyfor the "absent scope, no default configured"case (existing tests cover the fallback-succeeds case).
Check List (Check all the applicable boxes)
Note to reviewers
The 404 path only triggers when the default fallback can't be served (no
defaultscope, or its repo is unavailable) — the happy-path fallback to the default bundle is unchanged.black/isortclean; all three tests inscope_policy_fallback_test.pypass, and the new one fails onmasterwith the pre-fix 500 and passes with the fix.