From d1e324044216a0099984abce995e7bdbc4457a53 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sun, 9 Aug 2026 10:01:06 +1200 Subject: [PATCH] fix(queries): pass Filter arguments in the correct positions Filter's second parameter is $idAttributeType and $maxValuesCount is third, but Base passed APP_DATABASE_QUERY_MAX_VALUES second. Neither file declares strict_types, so the int 500 was silently coerced to the string "500" for $idAttributeType and $maxValuesCount kept its 5000 default, letting every console-collection query carry ten times the intended number of values. Named arguments so a future signature change fails loudly instead of sliding into the wrong slot, matching how the utopia Documents validator and cloud's ActivityEvents already build Filter. $idAttributeType is Database::VAR_INTEGER because the console database is SQL, whose adapters all report that type, and Base already declares its own $sequence attribute as VAR_INTEGER. Co-Authored-By: Claude Opus 5 --- .../Database/Validator/Queries/Base.php | 6 ++- .../Database/Validator/Queries/BaseTest.php | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/unit/Utopia/Database/Validator/Queries/BaseTest.php diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 9d9bbde00b..dffb1f6b48 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -91,7 +91,11 @@ class Base extends Queries new Limit(), new Offset(), new Cursor(), - new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), + new Filter( + attributes: $attributes, + idAttributeType: Database::VAR_INTEGER, + maxValuesCount: APP_DATABASE_QUERY_MAX_VALUES + ), new Order($attributes), ]; diff --git a/tests/unit/Utopia/Database/Validator/Queries/BaseTest.php b/tests/unit/Utopia/Database/Validator/Queries/BaseTest.php new file mode 100644 index 0000000000..88223b7e4e --- /dev/null +++ b/tests/unit/Utopia/Database/Validator/Queries/BaseTest.php @@ -0,0 +1,53 @@ +assertTrue( + $validator->isValid([Query::equal('userId', $values)]), + $validator->getDescription() + ); + } + + public function testQueryOverMaxValuesIsInvalid(): void + { + $validator = new Presences(); + $values = \array_fill(0, APP_DATABASE_QUERY_MAX_VALUES + 1, 'user'); + + $this->assertFalse( + $validator->isValid([Query::equal('userId', $values)]), + 'Query with ' . \count($values) . ' values must exceed the ' . APP_DATABASE_QUERY_MAX_VALUES . ' value cap' + ); + $this->assertStringContainsString( + 'greater than ' . APP_DATABASE_QUERY_MAX_VALUES . ' values', + $validator->getDescription(), + 'Rejection must be reported against the configured cap, not the validator default' + ); + } + + public function testSequenceTypedAttributeIsValidated(): void + { + $validator = new Presences(); + + $this->assertTrue( + $validator->isValid([Query::equal('userInternalId', [1])]), + $validator->getDescription() + ); + $this->assertFalse( + $validator->isValid([Query::equal('userInternalId', [1.5])]), + 'Fractional value must not validate against a sequence attribute' + ); + } +}