mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
5d1e08464b
commit
d1e3240442
2 files changed
+58
-1
No files matched your search
@@ -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),
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Utopia\Database\Validator\Queries;
|
||||
|
||||
use Appwrite\Utopia\Database\Validator\Queries\Presences;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Database\Query;
|
||||
|
||||
final class BaseTest extends TestCase
|
||||
{
|
||||
public function testQueryAtMaxValuesIsValid(): void
|
||||
{
|
||||
$validator = new Presences();
|
||||
$values = \array_fill(0, APP_DATABASE_QUERY_MAX_VALUES, 'user');
|
||||
|
||||
$this->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'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user