Repository navigation
fix(graphql): return validation error for anonymous malformed queries instead of 500 - #2579
Open
sentry[bot] wants to merge 1 commit into
Open
sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2579 +/- ##
=======================================
Coverage 91.64% 91.65%
=======================================
Files 1341 1341
Lines 53339 53344 +5
Branches 1649 1649
=======================================
+ Hits 48885 48890 +5
Misses 4133 4133
Partials 321 321
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This branch has not been deployed
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.
Problem
When an anonymous client executes a GraphQL query requesting non-existent fields (such as
TestResult.lastRun), schema validation raises aGraphQLError("Cannot query field ...").In
graphql_api/views.py,error_formatteronly treated bad queries as client-side errors whennot is_anonymous. For anonymous users, these validation errors fell through to the unhandled exception branch, which logged aGraphQL internal server error, reported the error to Sentry viacapture_exception, and responded to the client withINTERNAL SERVER ERROR(500).Fix
is_bad_querywhen the user is anonymous inerror_formatter.Bad Request/ValidationErrorto anonymous users (avoiding schema disclosure / suggestions) instead ofINTERNAL SERVER ERROR.log.errortolog.warningwith validation details, and avoid invokingcapture_exceptionfor harmless malformed client queries.test_when_bad_query_and_anonymousingraphql_api/tests/test_views.pyto match the new behavior.Legal Boilerplate
Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this 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 Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.
Fixes API-FAR
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this runThis PR was automatically generated by Sentry. You can adjust this setting at any time.
Note
Low Risk
Narrows error handling for anonymous malformed GraphQL queries only; reduces false Sentry noise and improves client-facing semantics without changing authenticated behavior.
Overview
Anonymous GraphQL clients that request non-existent fields were incorrectly treated as server failures: responses said INTERNAL SERVER ERROR, errors went to Sentry, and logging used the internal-error path.
error_formatternow handles schema validation failures (Cannot query field…) for anonymous users the same way as a client mistake: the API returns a genericBad RequestwithValidationError, without exposing schema details. Those cases are logged at warning with validation metadata and no longer hitcapture_exception/ the internal-server-error branch.The anonymous bad-query test is updated to assert the new message and error type.
Reviewed by Cursor Bugbot for commit a1ebd5b. Bugbot is set up for automated code reviews on this repo. Configure here.