GraphQl: Prevent infinite query loop on unexpected responses - #355
Draft
BigRoy wants to merge 1 commit into
Draft
Conversation
- Response with 'data: null' did not change pagination state, so the same query was sent again forever. Raise GraphQlQueryError with the query instead. - Page reporting another page without a cursor reset the cursor to 'None', so pagination started again from the first page. Stop pagination of the field with a warning. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
iLLiCiTiT
reviewed
Sep 14, 2026
| if change_cursor and self._need_query: | ||
| if new_cursor is None: | ||
| # Without cursor the pagination would start from beginning | ||
| log.warning( |
Member
There was a problem hiding this comment.
Shouldn't this raise GraphQlQueryError?
Member
Author
There was a problem hiding this comment.
I'm actually not sure how this could ever happen. This could happen if the result returned no cursor, or? So it'd be a response issue then, perhaps? 🤔 Is the GraphQlQueryError also for response issues, or query-specific problem?
But - yes... probably?
Member
There was a problem hiding this comment.
That is only for nested queries, which we don't use, so I believe AI in this case.
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.
Bug
Two unexpected (but valid-JSON) GraphQl responses make
GraphQlQuery.query()/continuous_query()loop forever, sending the same request to the server again and again:dataisnull(or missing).hasNextPage: truewithout anendCursor(e.g. an empty page).Neither is produced by a healthy server in normal use, but when it happens the client hangs (and hammers the server) instead of failing with an error that can be debugged.
Cause
parse_result(None, ...)returns immediately, so no field changes itsneed_querystate and thewhile self.need_queryloop repeats the identical query.None, which means "start from the beginning", so pagination restarted from the first page. (On the very first page it instead raised the misleading "Cursor didn't change" error.)Fix
_query_datahelper (it was copy-pasted three times). It raisesGraphQlQueryErrorincluding the response, query and variables whendatais missing.Reproduce
Not reproducible against a healthy server.
tests/test_graphql_infinite_loop.pyuses a scripted fake connection returning these responses; on develop the fake connection raises "Infinite query loop" after 10 identical requests.Testing notes
pytest tests/test_graphql_infinite_loop.py.get_folders,get_versions,get_eventsreturn the same results as before.🤖 Generated with Claude Code