fix: comment cursor throws on COMMENT_PARENT orderby pagination#3964
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
3 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3964 +/- ##
=======================================
Coverage 83.6% 83.6%
Complexity 5330 5330
=======================================
Files 286 286
Lines 22866 22866
=======================================
+ Hits 19106 19111 +5
+ Misses 3760 3755 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The CommentObjectCursor fallback compare field used the array key 'by' instead of 'value'. When all comments share a comment_parent (top-level comments, where comment_parent is 0), the orderby comparison adds no field and the cursor falls back to comparing by comment_date. The malformed fallback field failed the cursor compare validator, throwing an InvariantViolation on any page past the first. Use the expected 'value' key so the comment_date fallback comparison is applied correctly. Adds a regression test that paginates a comment connection ordered by COMMENT_PARENT past the first page and asserts no error is returned. Closes #3068
46e5772 to
64bf5a1
Compare
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.
What
Fixes #3068.
CommentObjectCursor::get_where()builds a fallback cursor-compare field when no orderby has populated the query builder. That fallback array used the key'by'instead of the'value'key thatAbstractCursor::compare_with_cursor_fields()(and its validatorvalidate_cursor_compare_field()) require.This surfaces when every comment in the connection shares the same
comment_parent, which is the common case of top-level comments wherecomment_parentis0. Ordering byCOMMENT_PARENTthen adds no comparison field (0 is treated as empty), so the cursor falls back to comparing bycomment_date. The malformed fallback field failed validation and threw anInvariantViolationon any page past the first.Fix
One-line change: use the expected
'value'key so thecomment_datefallback comparison is applied correctly.Test
Adds a regression test in
CommentConnectionQueriesTestthat paginates a comment connection ordered byCOMMENT_PARENTpast the first page using the cursor, and asserts no error is returned and that the second page does not repeat first-page nodes. The test fails before the fix (theafterquery returns anerrorsarray) and passes after.