You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: preserve request context when reordering documents - #19539
Fix incorrect order keys when reordering a join whose relationship points to different parents in different locales. For example, with an English default locale, a request to /reorder?locale=nb resolves the target's Norwegian parent but looks for its neighbor in English. If that parent has no English children, the lookup misses the existing Norwegian neighbor and assigns a colliding order key.
Pass req to the adjacent-document lookup so target reads, neighbor reads, and writes share the request locale and context. This bug reproduces on main with branching disabled.
Changes
Preserve request context in the adjacent-document query.
Add integration regressions for moving before and after a target through a localized join. They verify the key lies strictly between its neighbors and the populated join returns the requested order.
Test Plan
Verified on SQLite:
Before the fix: both new regression cases failed at the order-key boundary assertions.
After the fix: PAYLOAD_DATABASE=sqlite pnpm run test:int test/sort/orderable-locale.int.spec.ts --run — 2 passed.
Formatting and whitespace checks passed. Targeted lint passed with an existing unused Field import warning in the endpoint module.
Other database adapters were not tested locally.
Related work
Standalone prerequisite for the content branching review stack tracked in #19112. The same omitted request context also causes the neighbor query to use main when reordering on a content branch. This PR targets main and has no dependency on branching; branch-specific coverage remains separate in #19538.
No actionable comments were generated in the recent review.
Walkthrough
The reorder handler now passes req to its adjacent-document lookup. Integration tests cover greater and less reorder operations with the Norwegian locale.
Changes: Localized reorder operations
Layer / File(s)
Summary
Adjacent lookup and localized reorder validation packages/payload/src/config/orderable/index.ts, test/sort/orderable-locale.int.spec.ts, test/sort/int.spec.ts
The adjacent-document lookup receives req. Integration tests check Norwegian-locale reorder responses, moved document order keys, and joined document order. The prior localized reorder test was removed.
Reordering documents through a localized join now uses the requested locale when looking up the neighboring document. This avoids order keys that collide with neighbors in another locale. The change is small and covered by new regression tests, so it is ready to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix: preserve request context when reordering documents" matches the main change. The PR passes req to the adjacent-document lookup in the reorder handler so reads and writes use the requ…
Description check
The description explains the bug: a reorder request with locale=nb on a localized join resolves the Norwegian parent but looks up the neighbor in English, which can assign a colliding order key. It …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix: preserve request context when reordering documents" matches the main change. The PR passes req to the adjacent-document lookup in the reorder handler so reads and writes use the request locale and context. The title is specific and concise.
Full details: Description check
Explanation
The description explains the bug: a reorder request with locale=nb on a localized join resolves the Norwegian parent but looks up the neighbor in English, which can assign a colliding order key. It states the fix passes req to the adjacent-document lookup and lists the added integration regressions. It also gives test results and related work, so it relates directly to the changeset.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between 4c1f8b4 and 0c1b6ed.
Files selected for processing: 2
packages/payload/src/config/orderable/index.ts
test/sort/int.spec.ts
Files with no reviewable changes: 1
test/sort/int.spec.ts
Files skipped from review as they are similar to previous changes: 1
packages/payload/src/config/orderable/index.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Written with AI
LGTM! I removed the old localized reorder test in int.spec.ts because it returned a1 with or without the fix (your new spec covers it properly), and dropped the unused Field import.
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
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.
Written with AI
Description
Fix incorrect order keys when reordering a join whose relationship points to different parents in different locales. For example, with an English default locale, a request to
/reorder?locale=nbresolves the target's Norwegian parent but looks for its neighbor in English. If that parent has no English children, the lookup misses the existing Norwegian neighbor and assigns a colliding order key.Pass
reqto the adjacent-document lookup so target reads, neighbor reads, and writes share the request locale and context. This bug reproduces on main with branching disabled.Changes
Test Plan
Verified on SQLite:
PAYLOAD_DATABASE=sqlite pnpm run test:int test/sort/orderable-locale.int.spec.ts --run— 2 passed.PAYLOAD_DATABASE=sqlite pnpm run test:int test/sort/int.spec.ts --run— 44 passed.Fieldimport warning in the endpoint module.Other database adapters were not tested locally.
Related work
Standalone prerequisite for the content branching review stack tracked in #19112. The same omitted request context also causes the neighbor query to use main when reordering on a content branch. This PR targets main and has no dependency on branching; branch-specific coverage remains separate in #19538.