Repository navigation
fix(documents): set the collection on found rows before decoding them - #1099
Conversation
find() decoded each row before it set $collection, so a decode filter that asked $document->getCollection() got an empty string on every list read but the right id on getDocument(). Appwrite's subQueryVariables filter keys on it to pick function or site variables, and fell back to both, so listing sites returned the variables of a function with the same $sequence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code review
Walkthrough (2)
Reviewed Tip Comment |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
subQueryVariables chose function or site variables from $document->getCollection(), and fell back to both when it was empty. utopia-php/database decodes find() rows before it sets $collection, so on every list read the filter returned the variables of whichever function and site shared the document's $sequence. Dedicated tables give a project's first function and first site the same $sequence, so GET /v1/sites showed the function's variables, secrets included, and GET /v1/functions the site's. An unknown collection now yields no variables. List responses carry an empty vars until utopia-php/database sets $collection before decoding (utopia-php/database#1099); getDocument() reads, which every build and runtime path uses, are unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With 10.3.6, find() decodes rows before setting $collection, so the fail-closed variables filter left every site and function list response without its own vars. Pin the fix branch (utopia-php/database#1099) until it is released, and assert each list keeps exactly its own variables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Rust port has the same two defects as PHP: utopia-database find() decoded rows before setting $collection, and appwrite-core's subQueryVariables fell back to both function and site variables when the collection was empty. Set the collection before decoding, as the PHP fix (utopia-php/database#1099) does, which also keeps find() output key order the same as PHP's for the parity suites, and return no variables for an unknown collection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Problem
find()decoded each row before setting$collectionon it. A decode filter that reads$document->getCollection()got''on everyfind(), but the right collection id ongetDocument(),createDocument(),updateDocument()and upserts, which all set it first.Appwrite's
subQueryVariablesfilter reads it to choose function or site variables. On''it falls back to both, soGET /v1/sitesreturned the variables of a function with the same$sequence, and the other way round (appwrite/appwrite#16395).Fix
Set
$collectionon each found row beforedecode(), as the single-document paths already do. The value that ends up on the result is unchanged.Tests
tests/unit/FilterCollectionTest.phprecords the collection a decode filter sees throughgetDocument()andfind(), with and without a selection, on Memory and SQLite. It fails onmain(the filter sees''throughfind()) and passes with the fix. Locally, the other unit failures (EvictionProtocolTest,BaseAdapterStateTest,SwooleAbsentTest) happen with and without this change: they need Redis and Swoole, which the machine doesn't have.🤖 Generated with Claude Code
Summary by CodeRabbit