Repository navigation
fix(query): refuse ordering by a relationship that holds no column - #1023
Merged
Merged
Conversation
A one-to-many parent, a many-to-one child and either side of a many-to-many keep their related ids on the other collection or in a junction table, so their collection has no column to order by. The order validator accepted every relationship key, the engine then failed on the unknown column, and the read surfaced that as NotFound "Attribute not found", which a consumer answers as a missing collection. The validator now marks those keys from Joined\Collection::columns(), which already tells which side of a relationship stores its column, and refuses an orderAsc() or orderDesc() on them with "Cannot order by relationship attribute: <key>", the QueryException every other invalid order raises. Relationships that hold a column order as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
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. Comment |
ArnabChatterjee20k
pushed a commit
to ArnabChatterjee20k/appwrite
that referenced
this pull request
Oct 15, 2026
…he library countRows() re-ran a grouped, distinct or aggregate read for up to APP_LIMIT_COUNT rows because count() ignored groupBy, distinct and aggregates. utopia-php/database#1020 counts them by their rows, so the total goes back to count() with APP_LIMIT_COUNT. The relationship order validator and its unit tests go too: utopia-php/database#1023 refuses ordering by a relationship that holds no column with the same message, as a QueryException the list already answers with 400 general_query_invalid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A one-to-many parent, a many-to-one child and either side of a many-to-many keep their related ids on the other collection or in a junction table. Their own collection has no column to sort on. The order validator accepted every relationship key anyway. The engine then failed on the unknown column, and
find()andcount()surfaced it as:Appwrite answered that as a 404 for the whole collection. appwrite/appwrite#14543 works around it with its own
Validator\Query\Order. This moves the check into the library so that class can go.Fix
The
Ordervalidator now marks the relationship keys that hold no column, usingJoined\Collection::columns(). That function already knows which side of each relationship stores its column. AnorderAsc()ororderDesc()on one of those keys is refused with theQueryExceptionevery other invalid order raises:Relationships that hold a column (a one-to-many child, a many-to-one parent, a one-to-one parent, a two-way one-to-one child) order as before.
Tests
tests/unit/RelationshipOrderTest.phpruns on SQLite and covers:orderAscandorderDesc, throughfind()andcount().On
main, the four refused cases fail withNotFound: Attribute not found. They pass with the fix. The validator unit suite (964 tests) and the relationship/order E2Es on SQLite (243 tests) pass. Pint and PHPStan are clean on the changed files.🤖 Generated with Claude Code