Skip to content

fix(metrics): Return 400 for invalid metric MRI use_case_id - #119123

Open
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/metrics-invalid-mri-400
Open

fix(metrics): Return 400 for invalid metric MRI use_case_id#119123
sentry[bot] wants to merge 1 commit into
masterfrom
seer/fix/metrics-invalid-mri-400

Conversation

@sentry

@sentry sentry Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor
Currently, when an API client queries `/api/0/organizations/{organization_id_or_slug}/metrics/data/` with a metric MRI containing an unrecognized `use_case_id` namespace (e.g., `c:app/memory_warning@none`), the `_use_case_id` method in `sentry/snuba/metrics/query.py` raises a generic `ValueError`.

This ValueError is not caught by the API endpoint's specific exception handlers for bad input, leading to it being re-raised as an unhandled exception. As a result, the API returns a 500 Internal Server Error instead of a more appropriate 400 Bad Request, and logs a Sentry event for what is essentially invalid client input.

This change modifies _use_case_id to raise InvalidParams instead of ValueError. The InvalidParams exception is already handled by the API endpoint to return a 400 Bad Request, providing a clearer and more correct response to clients and reducing noise in Sentry.

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-5D8V

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@sentry
sentry Bot requested review from a team as code owners July 7, 2026 15:43
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 7, 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