feat(relay): add offset argument to relay connection (#339) - #956
Open
mini0n-ai wants to merge 1 commit into
Conversation
Member
|
Thanks for adding the Below is the changelog that will be used for the release. Add This release was contributed by @mini0n-ai in #956 |
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="strawberry_django/relay/list_connection.py" line_range="104-108" />
<code_context>
field_ = unwrap_type(field_)
edge_class = cast("Edge", field_)
+ after = resolve_offset_to_after(
+ field_kwargs.get("offset"),
+ field_kwargs.get("after"),
+ prefix=edge_class.CURSOR_PREFIX,
+ )
slice_metadata = SliceMetadata.from_arguments(
Info(_raw_info=info, _field=field),
</code_context>
<issue_to_address>
**issue (bug_risk):** For optimized queryset connections using the `last`-only path, `offset` is first folded into `after` and then forwarded unchanged to `resolve_optimized_last_connection`, whose recursive `resolve_connection` folds the same offset into the already-adjusted cursor a second time. The query therefore starts too far into the list and returns the wrong page.
**Triggers:** When a queryset-backed list connection is optimized and queried with `last` plus a positive `offset` and no `before` cursor.
**Suggested fix:** Pass the original `after` and offset only once, or clear `offset` after converting it into `after` before entering `resolve_optimized_last_connection`.
```suggestion
after = resolve_offset_to_after(
offset,
after,
prefix=edge_class.CURSOR_PREFIX,
)
offset = None
```
</issue_to_address>
### Comment 2
<location path="strawberry_django/relay/cursor_connection.py" line_range="260-261" />
<code_context>
if first > max_results:
raise ValueError(f"Argument 'first' cannot be higher than {max_results}.")
- slice_ = slice(first + 1)
+ start = offset or 0
+ slice_ = slice(start, start + first + 1)
elif last is not None:
# when using last, optimize by reversing the QuerySet ordering in the DB,
</code_context>
<issue_to_address>
**issue (bug_risk):** Negative offsets are not validated in cursor-backed connections before constructing the queryset slice. For nested connections that use window pagination, the negative offset is treated as a valid row-number boundary and returns an incorrect page instead of raising the required non-negative-offset error.
**Triggers:** When a cursor connection is nested or otherwise uses `related_field_id` and receives `offset < 0`.
**Suggested fix:** Validate `offset < 0` in `apply_cursor_pagination` before applying either queryset slicing or window pagination.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: strawberry_django/relay/list_connection.py:108, strawberry_django/relay/cursor_connection.py:261
mini0n-ai
force-pushed
the
fix/bounty-polar-strawberry-graphql-strawberry-graphql-django-339-339
branch
from
September 12, 2026 11:55
a208296 to
89ea6dd
Compare
Member
|
Hi @mini0n-ai , I'm trying to understand, what the use case of |
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.
Summary
Add argument to relay connections, enabling first/offset pagination with proper ( and ) tracking.
Resolves #339
/claim #339
Details
Settlement
Summary by Sourcery
Enable offset-based pagination for Relay connections while preserving cursor pagination semantics and accurate page metadata.
New Features:
offsetargument to Relay connections for offset-based pagination alongside cursor pagination.Bug Fixes:
Enhancements:
aftercursors.Tests: