Compare commits

..
Author SHA1 Message Date
ArnabChatterjee20k 737c85822d multi line comment 2026-05-04 12:46:44 +05:30
ArnabChatterjee20k 1fc3a8803c multiline comment 2026-05-04 12:45:32 +05:30
ArnabChatterjee20k c32294743a reverted e2e 2026-05-04 12:31:50 +05:30
ArnabChatterjee20k f5a7cfd2ea fix: resolve query syntax errors and improve error handling in Request class 2026-05-04 12:22:48 +05:30
Luke B. SilverandGitHub 76e6239d32 Merge pull request #12204 from appwrite/chore/bump-image-1.4.1
chore: bump base image to 1.4.1
2026-05-03 20:18:03 +01:00
Matej BačoandGitHub 1da5b549af Merge pull request #12203 from appwrite/fix-missing-scopes-console
Fix: Add deprecated function scopes
2026-05-03 20:21:28 +02:00
loks0nandClaude Opus 4.7 92eceba218 chore: bump base image to 1.4.1
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 19:21:00 +01:00
4 changed files with 169 additions and 29 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist \
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`
FROM appwrite/base:1.3.1 AS base
FROM appwrite/base:1.4.1 AS base
LABEL maintainer="team@appwrite.io"
+39 -28
View File
@@ -51,38 +51,49 @@ class Request extends UtopiaRequest
if (!\is_array($methods)) {
$id = $methods->getNamespace() . '.' . $methods->getMethodName();
} else {
$matched = null;
foreach ($methods as $method) {
/** @var Method|null $method */
if ($method === null) {
continue;
}
// Find the method that matches the parameters passed
$methodParamNames = \array_map(fn ($param) => $param->getName(), $method->getParameters());
$invalidParams = \array_diff(\array_keys($parameters), $methodParamNames);
// No params defined, or all params are valid
if (empty($methodParamNames) || empty($invalidParams)) {
$matched = $method;
break;
}
}
$id = $matched !== null
? $matched->getNamespace() . '.' . $matched->getMethodName()
: 'unknown.unknown';
}
try {
foreach ($this->getFilters() as $filter) {
$parameters = $filter->parse($parameters, $id);
}
$this->filteredParams = $parameters;
return $parameters;
}
$matched = null;
foreach ($methods as $method) {
/** @var Method|null $method */
if ($method === null) {
continue;
} catch (\Throwable $e) {
/*
* 4xx filter throws are user-input errors that the action layer
* revalidates and reports. Cache the raw, pre-filter parameters
* so a subsequent getParams() — e.g. when the framework builds
* arguments for an error hook — returns without re-running
* filters. Otherwise the second throw gets wrapped as
* "Error handler had an error: ..." (HTTP 500), masking the
* intended 400.
*/
$code = $e->getCode();
if (\is_int($code) && $code >= 400 && $code < 500) {
$this->filteredParams = $parameters;
}
// Find the method that matches the parameters passed
$methodParamNames = \array_map(fn ($param) => $param->getName(), $method->getParameters());
$invalidParams = \array_diff(\array_keys($parameters), $methodParamNames);
// No params defined, or all params are valid
if (empty($methodParamNames) || empty($invalidParams)) {
$matched = $method;
break;
}
}
$id = $matched !== null
? $matched->getNamespace() . '.' . $matched->getMethodName()
: 'unknown.unknown';
// Apply filters
foreach ($this->getFilters() as $filter) {
$parameters = $filter->parse($parameters, $id);
throw $e;
}
$this->filteredParams = $parameters;
@@ -0,0 +1,24 @@
<?php
namespace Tests\Unit\Utopia\Request\Filters;
use Appwrite\Utopia\Request\Filter;
/**
* Test fixture: a filter that always throws, with a configurable code.
* Used to assert how Request::getParams() reacts to filter exceptions.
*/
class ThrowingFilter extends Filter
{
public int $calls = 0;
public function __construct(private int $code, private string $reason)
{
}
public function parse(array $content, string $model): array
{
$this->calls++;
throw new \Exception($this->reason, $this->code);
}
}
+105
View File
@@ -5,10 +5,12 @@ namespace Tests\Unit\Utopia;
use Appwrite\SDK\Method;
use Appwrite\SDK\Parameter;
use Appwrite\Utopia\Request;
use Appwrite\Utopia\Request\Filter;
use PHPUnit\Framework\TestCase;
use Swoole\Http\Request as SwooleRequest;
use Tests\Unit\Utopia\Request\Filters\First;
use Tests\Unit\Utopia\Request\Filters\Second;
use Tests\Unit\Utopia\Request\Filters\ThrowingFilter;
use Utopia\Http\Route;
class RequestTest extends TestCase
@@ -192,6 +194,109 @@ class RequestTest extends TestCase
$this->assertSame('fallback', $request->getHeader('referer', 'fallback'));
}
public function testGetParamsCachesRawParamsWhenFilterThrows4xx(): void
{
/*
* Regression: when a request filter throws a 4xx exception during
* Request::getParams() (e.g. RequestV20 rejecting an unparseable
* queries[]), the framework's error path calls getParams() again to
* build error-hook arguments. Without caching, that second call
* re-runs the filter and re-throws, which the framework wraps as
* "Error handler had an error: ..." (HTTP 500), masking the intended
* 400. This test pins that behavior: the first call throws (so the
* action's argument resolution aborts), but the second call returns
* the raw, pre-filter params without re-invoking filters.
*/
$filter = new ThrowingFilter(400, 'invalid input');
$this->setupSingleMethodRoute($filter);
$this->request->setQueryString(['foo' => 'bar']);
$threw = false;
try {
$this->request->getParams();
} catch (\Throwable $e) {
$threw = true;
$this->assertSame(400, $e->getCode());
$this->assertSame('invalid input', $e->getMessage());
}
$this->assertTrue($threw, 'First getParams() call must rethrow the filter exception.');
$this->assertSame(1, $filter->calls, 'Filter ran once on the first call.');
// Second call: framework's error hook arg resolution. Must return raw
// params without re-invoking the filter.
$params = $this->request->getParams();
$this->assertSame(['foo' => 'bar'], $params);
$this->assertSame(1, $filter->calls, 'Filter must not run again after a cached 4xx failure.');
}
public function testGetParamsDoesNotCacheRawParamsForServerError(): void
{
/*
* 5xx filter throws indicate genuine server-side problems, not
* user-input mistakes. They must keep rethrowing on every call so
* the framework's normal error handling sees the failure each time
* — caching raw params would silently swallow real bugs.
*/
$filter = new ThrowingFilter(500, 'boom');
$this->setupSingleMethodRoute($filter);
$this->request->setQueryString(['foo' => 'bar']);
for ($attempt = 1; $attempt <= 2; $attempt++) {
$threw = false;
try {
$this->request->getParams();
} catch (\Throwable $e) {
$threw = true;
$this->assertSame(500, $e->getCode());
}
$this->assertTrue($threw, "Call #$attempt must rethrow.");
$this->assertSame($attempt, $filter->calls, "Filter must run on call #$attempt.");
}
}
public function testGetParamsDoesNotCacheRawParamsForUncodedException(): void
{
// \Exception with the default code of 0 is treated as "unknown" and
// must propagate every call — same reasoning as 5xx.
$filter = new ThrowingFilter(0, 'unknown');
$this->setupSingleMethodRoute($filter);
$this->request->setQueryString(['foo' => 'bar']);
for ($attempt = 1; $attempt <= 2; $attempt++) {
$threw = false;
try {
$this->request->getParams();
} catch (\Throwable) {
$threw = true;
}
$this->assertTrue($threw, "Call #$attempt must rethrow.");
$this->assertSame($attempt, $filter->calls, "Filter must run on call #$attempt.");
}
}
/**
* Helper to attach a route with a single SDK method and one filter.
*/
private function setupSingleMethodRoute(Filter $filter): void
{
$route = new Route(Request::METHOD_GET, '/single');
$route->label('sdk', new Method(
namespace: 'namespace',
group: 'group',
name: 'method',
description: 'description',
auth: [],
responses: [],
));
$this->request->addHeader('EXAMPLE', 'VALUE');
$this->request->setRoute($route);
$this->request->addFilter($filter);
}
/**
* Helper to attach a route with multiple SDK methods to the request.
*/