fix(api): Handle non-dict payload for project symbol sources PUT#119158
Open
sentry[bot] wants to merge 1 commit into
Open
fix(api): Handle non-dict payload for project symbol sources PUT#119158sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Comment on lines
+401
to
+402
| return Response(data={"detail": "Invalid request body"}, status=400) | ||
|
|
Contributor
Author
There was a problem hiding this comment.
Bug: The new validation check returns an error response with a detail key, while the rest of the endpoint consistently uses an error key, breaking the documented API contract.
Severity: MEDIUM
Suggested Fix
To ensure API consistency and maintain backward compatibility, modify the error response to use the error key instead of detail. Change the response to return Response(data={"error": "Invalid request body"}, status=400).
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/api/endpoints/project_symbol_sources.py#L401-L402
Potential issue: The new validation check in the `put` method returns an error response
using the format `{"detail": "..."}`. This is inconsistent with the rest of the
endpoint, which uses the `{"error": "..."}` format for all other errors. This violates
the documented API contract, as specified by the `_SymbolSourceErrorResponse` TypedDict
and the method's return type annotation. The documentation explicitly states the
`{"error": ...}` format is retained for backward compatibility, so this change could
break existing API consumers that expect the `error` key in all error responses from
this endpoint.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
This PR addresses a
TypeError: list indices must be integers or slices, not strthat occurs when thePUT /api/0/projects/{organization_id_or_slug}/{project_id_or_slug}/symbol-sources/endpoint receives a JSON array as its request body instead of the expected JSON object.The root cause was that the endpoint's
put()method directly assignedrequest.datatosourceand then attempted to accesssource["id"]without validating thatsourcewas a dictionary. Ifrequest.datawas a list, this would lead to theTypeError.The fix introduces a type check at the beginning of the
put()method insrc/sentry/api/endpoints/project_symbol_sources.py. Ifrequest.datais not an instance ofdict, the API now returns a400 Bad Requestresponse with a{"detail": "Invalid request body"}message, preventing theTypeErrorand providing a clearer error to the client.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-5R9Y
Comment
@sentry <feedback>on this PR to have Autofix iterate on the changes.