Skip to content

fix(documents): keep the collection as the last key of found rows - #1101

Merged
abnegate merged 2 commits into
mainfrom
fix/find-collection-before-decode
Dec 2, 2026
Merged

abnegate merged 2 commits into
mainfrom
fix/find-collection-before-decode

Conversation

@abnegate

@abnegate abnegate commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

What

Follow-up to #1099. After find() decodes a row, $collection is re-appended so it stays the last key of each returned document, where find() has always returned it.

Why

#1099 set the collection on found rows before decoding them, which fixed filters that depend on it but moved $collection to a different position in the returned document. Consumers that compare the key order of find() output (for example recorded compatibility expectations) saw a behaviour change. These two commits were pushed to the branch after #1099 merged, so no release contains them yet and downstream projects have had to depend on the branch directly.

Changes

  • src/Database/Trait/Documents.php: re-append $collection after decoding a non-empty found row.
  • tests/unit/FilterCollectionTest.php: asserts $collection is the last key of a found row; narrows the populated owner before reading its id.

Testing

Covered by the unit test above; CI runs the full suites.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Document results now keep the collection identifier as the final field after custom conversion, including when related documents are decoded.

abnegate and others added 2 commits December 2, 2026 13:39
Setting $collection before decode() moved it ahead of relationship keys,
which decode() re-appends, so find() and the documents it populates changed
key order. Re-append it after decoding so the output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@appwrite

appwrite Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
ca0041b Reviewed Reviewed 🟢 S · Ready to merge ✅ Approved View review

The change re-appends $collection after decoding non-empty documents returned by find(). It adds adapter-backed unit coverage for the key order of a relationship-populated result.

Walkthrough (2)
File Change
src/Database/Trait/Documents.php Re-appends $collection after decoding and custom document conversion.
tests/unit/FilterCollectionTest.php Adds a test that checks $collection remains the last key of a found row.

Reviewed ca0041b

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

For non-empty documents, fetch now re-appends Document::COLLECTION after custom document conversion. An adapter-parameterized test checks that the related owner is decoded as a Document and that the collection key is last.

Changes: Document collection key ordering

Layer / File(s) Summary
Re-append collection key after conversion
src/Database/Trait/Documents.php, tests/unit/FilterCollectionTest.php
fetch removes and re-appends Document::COLLECTION after custom document conversion for non-empty documents. The test checks the decoded related owner and confirms the collection key is last.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

  • utopia-php/database#1099: Sets the collection on found rows before decoding in find(). This change extends the same code path by re-appending the collection key after decoding.

Suggested reviewers: appwrite, loks0n, fogelito

Merge Risk: Minimal · up to ca004

This change restores the collection key as the last key in documents returned by find(). It is a small, localized change with a regression test, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the collection key stays last in found rows. The raw summary says Documents.php re-appends Document::COLLECTION after custom conversion in fetch for non-empty documents, and the test ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says the collection key stays last in found rows. The raw summary says Documents.php re-appends Document::COLLECTION after custom conversion in fetch for non-empty documents, and the test checks the collection key remains last. The title matches the main change. The title uses a conventional commit prefix, which is acceptable.

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 93b63f1 and ca0041b.

Files selected for processing: 2

  • src/Database/Trait/Documents.php
  • tests/unit/FilterCollectionTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@abnegate
abnegate merged commit 5fd417c into main Dec 2, 2026
31 checks passed
@abnegate
abnegate deleted the fix/find-collection-before-decode branch December 2, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant