Skip to content

fix(js-sdk-loader): Gracefully handle Project.DoesNotExist for orphaned ProjectKeys#118228

Open
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/js-sdk-loader-project-does-not-exist
Open

fix(js-sdk-loader): Gracefully handle Project.DoesNotExist for orphaned ProjectKeys#118228
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/js-sdk-loader-project-does-not-exist

Conversation

@sentry

@sentry sentry Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the Project.DoesNotExist error occurring in the /js-sdk-loader/{public_key}{minified}.js endpoint.

Problem:
The JavaScriptSdkLoader.get() method would crash with Project.DoesNotExist if a ProjectKey was found (e.g., from cache) but the Project it referenced had been deleted. This happens when an orphaned ProjectKey exists, often due to a project being deleted while its DSN is still being requested by clients.

Solution:

  1. The Project.objects.get_from_cache(id=key.project_id) call (line 288 in js_sdk_loader.py) is now wrapped in a try/except Project.DoesNotExist block.
  2. If Project.DoesNotExist is caught, the key variable is explicitly set to None.
  3. This leverages the existing logic in the js_sdk_loader which already handles key = None by falling back to serving the noop SDK template (sentry/js-sdk-loader-noop.js.tmpl).
  4. A new metric, js-sdk-loader.orphaned_project_key, is incremented when this scenario occurs, providing observability into the frequency of orphaned ProjectKeys.

This change ensures that the JS SDK loader remains robust and serves a noop SDK instead of crashing, even when encountering DSNs for projects that no longer exist.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes SENTRY-3VXA

@sentry sentry Bot requested a review from a team as a code owner June 23, 2026 10:41
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants