Skip to content

fix(scopes): return 404 instead of 500 for a missing scope policy - #935

Open
sameer-soni wants to merge 1 commit into
permitio:masterfrom
sameer-soni:fix/scope-policy-404-919
Open

fix(scopes): return 404 instead of 500 for a missing scope policy#935
sameer-soni wants to merge 1 commit into
permitio:masterfrom
sameer-soni:fix/scope-policy-404-919

Conversation

@sameer-soni

Copy link
Copy Markdown

Fixes Issue

Closes #919

Changes proposed

GET /scopes/{scope_id}/policy falls back to the default scope bundle when the requested scope isn't found. If no default scope exists either, _generate_default_scope_bundle re-raised ScopeNotFoundError, which was never caught, so the route returned a 500 ("Uncaught server exception") for an unknown or not-yet-synced scope. The OPAL client hits this on connect (it fetches /scopes/{scope_id}/policy before the scope has synced), so it sees repeated 500s until the sync completes.

  • _generate_default_scope_bundle now raises HTTPException(404) instead of ScopeNotFoundError when neither the requested scope nor a default scope can be served, matching the existing get_scope / refresh_scope routes and the client's existing 404 handling.
  • Added a regression test in scope_policy_fallback_test.py for the "absent scope, no default configured"
    case (existing tests cover the fallback-succeeds case).

Check List (Check all the applicable boxes)

  • I sign off on contributing this submission to open-source
  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.

Note to reviewers

The 404 path only triggers when the default fallback can't be served (no default scope, or its repo is unavailable) — the happy-path fallback to the default bundle is unchanged. black/isort clean; all three tests in scope_policy_fallback_test.py pass, and the new one fails on master with the pre-fix 500 and passes with the fix.

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
@netlify

netlify Bot commented Jul 23, 2026

Copy link
Copy Markdown

Deploy Preview for opal-docs canceled.

Name Link
🔨 Latest commit 89b147f
🔍 Latest deploy log https://app.netlify.com/projects/opal-docs/deploys/6a6278db16d3830008f69627

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.

GET /scopes/{scope_id}/policy returns 500 (uncaught ScopeNotFoundError) for an unknown or not-yet-synced scope

1 participant