Skip to content

feat(api): Make InvalidParams a ParseError#112542

Merged
kcons merged 2 commits intomasterfrom
kcons/theothers
Apr 9, 2026
Merged

feat(api): Make InvalidParams a ParseError#112542
kcons merged 2 commits intomasterfrom
kcons/theothers

Conversation

@kcons
Copy link
Copy Markdown
Member

@kcons kcons commented Apr 8, 2026

InvalidParam is raised in API parsing contexts; we have 20+ cases already catching it and turning it into a 400, another 15 or so cases where we should be (prior to this change).
Rather than continuing to add that boilerplate, we can make InvalidParam a ParseError, so that the default behavior when parameters don't seem correct is a 400 response.
The existing uses that don't convert to a 400 still work as they did previously.

@kcons kcons requested a review from a team as a code owner April 8, 2026 21:58
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 8, 2026
Comment thread src/sentry/exceptions.py


class InvalidParams(Exception):
class InvalidParams(ParseError):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: By inheriting from ParseError, InvalidParams exceptions will be silently caught by existing handlers, preventing them from being reported to Sentry.
Severity: MEDIUM

Suggested Fix

Revert the inheritance change so that InvalidParams does not inherit from ParseError. This will ensure that InvalidParams exceptions are not caught by generic ParseError handlers and can be reported to Sentry as intended.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/exceptions.py#L93

Potential issue: Changing the `InvalidParams` exception to inherit from `ParseError`
causes it to be silently caught in exception handlers that are designed to catch
`ParseError`. An example of this is in `organization_events.py`. As a result,
`InvalidParams` exceptions will no longer be captured and reported to Sentry, leading to
a loss of observability for this error type.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true. The real question here is "given that these signal invalid parameters, why do we want to see them in Sentry?".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^ agree; i ran into this with a different kind of ValidationError and was surprised it didn't just work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit scary to change after there are already dozens of uses, but gosh we'd be better off if api-focused validation stuff produced the appropriate status code/response by default.

Comment thread src/sentry/snuba/metrics/fields/base.py Dismissed
@kcons kcons merged commit c8d30a3 into master Apr 9, 2026
63 checks passed
@kcons kcons deleted the kcons/theothers branch April 9, 2026 19:52
george-sentry pushed a commit that referenced this pull request Apr 9, 2026
InvalidParam is raised in API parsing contexts; we have 20+ cases
already catching it and turning it into a 400, another 15 or so cases
where we _should_ be (prior to this change).
Rather than continuing to add that boilerplate, we can make InvalidParam
a ParseError, so that the default behavior when parameters don't seem
correct is a 400 response.
The existing uses that don't convert to a 400 still work as they did
previously.
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.

3 participants