Repository navigation
fix(find): return only the selected attributes of a distinct row - #1032
Merged
Merged
Conversation
find() decoded every row with the read's selections, to which validateSelections() always appended $id, $sequence, $collection, $createdAt, $updatedAt and $permissions so a document read with a select still carries them. A distinct read selects only what its select names, so decode() set each of those it never read to null, and a distinct row carried `$id => null`. The library handed out a Document its own constructor refuses: `new Document($row->getArrayCopy())` threw "$id must be of type string", which is how Appwrite's list cache rebuilt a cached distinct read and answered 400 on every cache hit. A distinct read now decodes only the attributes it selects. A distinct row carries $id only when the read selects it, and every row find() returns rebuilds into an equal Document. 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 20 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 |
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
On staging, a distinct read with
ttlworked on the cache miss but returned400 "$id must be of type string"on every cache hit.The root cause is in the library.
find()decodes each row with the read's selections, andvalidateSelections()always appended$id,$sequence,$collection,$createdAt,$updatedAtand$permissionsto them. A distinct read selects only what itsselect()names, sodecode()set each internal attribute it never read tonull. A row fromfind([Query::distinct(), Query::select(['k'])])therefore carried$id => null, andnew Document($row->getArrayCopy())refused it. Appwrite's list cache rebuilds cached rows exactly that way.validateSelections()no longer appends the internal attributes for a distinct read. A distinct row carries only what it selects, plus$collection, and carries$idonly when the read selects it. Non-distinct reads are unchanged and still carry$idand the other internal attributes. Every rowfind()returns now round-trips throughnew Document($row->getArrayCopy()).Regression tests
DocumentTests::testDistinctRowsCarryOnlyWhatTheySelectAndRebuildIntoADocument: distinct ofk(including a null value), ofk+n, ofk+$createdAt, ofk+$id, distinct pages by cursor, and a non-distinct select; each row round-trips throughnew Document()Utopia\Database\Exception\Structure: $id must be of type stringException\Query; a non-distinct select round-trips)Run locally against Docker: the full adapter suites for MySQL, MariaDB, Postgres, SQLite, MongoDB, Memory and Redis pass, as do the full unit suite, Pint and PHPStan.
API repro (Appwrite)
GET /v1/tablesdb/{db}/tables/{t}/rows?queries[]={"method":"distinct"}&queries[]={"method":"select","values":["k"]}&ttl=60, called twice → both calls200; the second hasX-Appwrite-Cache: hit. Rows have no$idkey unlessselectnames$id(was 400"$id must be of type string"on the hit). Withselect(["k","$id"])every row carries a string$id.🤖 Generated with Claude Code