Skip to content

fix(api): pass loose boolean query params to actions as bools - #14551

Merged
abnegate merged 5 commits into
mainfrom
qfix-total-param
Oct 15, 2026
Merged

abnegate merged 5 commits into
mainfrom
qfix-total-param

Conversation

@abnegate

Copy link
Copy Markdown
Member

What

?total=false on a list endpoint was ignored: the total was still computed. ?total=0 worked.

Why

Query string values always arrive as strings. A param validated by a loose Boolean validator accepts "true", "false", "1" and "0", but the string reached the action unchanged. Http.php isn't strict_types, so PHP cast it at the bool argument: every non-empty string except "0" became true. This affects every loose Boolean query param, not only total.

Fix

After validation, the http dispatcher converts those four strings to real bools when the param's validator is Boolean. It unwraps Nullable and resolves factory validators first. This mirrors what the CLI dispatcher already does for getopt input. Other validators, defaults and non-string values pass through untouched.

Tests

  • packages/http unit tests cover each literal across plain, nullable and factory-built Boolean params, plus pass-through for other validators. They fail without the fix.
  • New E2E cases send the literal total=false / total=true strings on document, row and user lists. The existing E2E client builds query strings with http_build_query, which encodes false as "0", so the old tests never hit this path.
  • Also marks the back-compat Route::getMethod() test with #[IgnoreDeprecations], so the http suite runs without deprecation warnings.

🤖 Generated with Claude Code

abnegate and others added 4 commits October 15, 2026 22:11
Query string values always arrive as strings. A param validated by
Boolean(true) accepts "true", "false", "1" and "0" but used to reach the
action unchanged, and since Http.php is not strict_types PHP casts the
string at the `bool` argument: any non-empty string except "0" becomes
true. So `?total=false` computed the count while `?total=0` did not,
and the same held for every Boolean query param, not only `total`.

The http dispatcher now converts those four strings to real bools after
validation when the param's validator, unwrapped from Nullable and
resolved if it is a factory, is Boolean. This mirrors the coercion the
CLI dispatcher already does for getopt input. Other validators, defaults
and non-string values pass through untouched.

The existing E2E coverage missed this because the test client builds
query strings with http_build_query, which encodes false as "0". The new
E2E tests send the literal strings on documents, rows and users lists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 3 nitpicks below.

🧹 Nitpicks (3) — 🟢 3 low
  • 🟢 JSON int 1/0 skip boolean coercion (Http.php:918) — coerce() matches strictly on the raw value (packages/http/src/Http.php:918), so the string '1'/'0' from query strings becomes bool, but the integer 1/0 a JSON body produces falls through to default => null and stays an int.
  • 🟢 Resolve the param validator once, not twice (Http.php:916) — coerce() calls resolveValidator() again for every provided param whose value matches a boolean string, after validate() has already resolved the same validator for the same param (packages/http/src/Http.php:928).
  • 🟢 Coercion bypasses the skipValidation opt-out (Http.php:764) — The coerce() call runs whenever $paramExists, outside the !$param['skipValidation'] guard (packages/http/src/Http.php:764), so a param the author explicitly opted out of validating still gets 'true'/'1'/'0'/'false' silently rewritten to a real boolean.

This PR introduces a coerce() step in packages/http/src/Http.php that converts the string values 'true'/'1'/'false'/'0' to real booleans for params validated as Boolean (including through Nullable wrappers), applied only when the param was actually provided in the request.

Files Change
packages/http/src/Http.php Adds coerce() and wires it into getArguments() before setParamValue, plus a phpstan baseline entry for the mixed-to-array parameter.
packages/http/tests/HttpTest.php Adds a data-provider test covering boolean coercion across Boolean, Nullable(Boolean) and factory validators, plus no-op and omitted-default cases.
packages/http/tests/RouteTest.php Adds #[IgnoreDeprecations] to silence deprecation noise in an existing test.
tests/e2e/Services/Databases/DatabasesBase.php Adds testListDocumentsTotalAcceptsBooleanStrings asserting the total query param accepts boolean strings across list-documents.
tests/e2e/Services/Users/UsersBase.php Adds testListUsersTotalAcceptsBooleanStrings with the same contract for the users list endpoint.
packages/http/phpstan-baseline.neon Baselines the new mixed-to-array argument type on coerce().

Reviewed commit: 0bbad81

@ghost

ghost commented Oct 15, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes preserve the intended validator and skip-validation behavior, with regression coverage for the changed paths.

The HTTP dispatcher now passes recognized loose-Boolean values to actions as native booleans, including nullable and factory-built validators. Unit and E2E tests cover the conversion and its pass-through cases, and the legacy route accessor test ignores deprecation notices.

Latest changes: The newest commits move coercion into the validation path, convert integer 0/1 values for loose Boolean params, and add a test confirming skipped validation preserves the original string.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
packages/http/phpstan-baseline.neon Adds the PHPStan baseline entry for the Boolean coercion helper.
packages/http/src/Http.php Coerces recognized Boolean values after successful validation, resolving factories and Nullable validators.
packages/http/tests/HttpTest.php Covers string and integer Boolean values, validator wrappers, passthrough behavior, defaults, and skipped validation.
packages/http/tests/RouteTest.php Ignores deprecation notices in the compatibility test for the legacy route accessor.
tests/e2e/Services/Databases/DatabasesBase.php Adds list-total E2E cases using literal Boolean query strings for documents and rows.
tests/e2e/Services/Users/UsersBase.php Adds user-list E2E cases using literal Boolean query strings.

Reviewed the commits since 0bbad81 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → qfix-total-param (after).

Metric Before After Change
🚀 Requests/sec 201.41 205.97 ⚪ +2.3%
⏱️ Latency P50 84.93 ms 83.38 ms ⚪ -1.8%
⏱️ Latency P95 201.36 ms 199 ms ⚪ -1.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 83.38 199 12,825 205.97 -2.36
Account 157.73 311.47 675 11.14 -5.46
TablesDB 79.17 148.65 6,975 113.88 -14.31
Storage 78.72 175.96 3,375 57.23 +2.31
Functions 125.19 248.8 1,800 31.22 -11.8

Top API waits (after)

API request Max wait (ms)
functions.create 451.55
functions.variables.update 421.12
functions.variables.delete 420.61
account.prefs.update 418.2
account.name.update 411.03

…ched

A loose Boolean validator also accepts the integers 1 and 0 a JSON body sends,
so they now reach the action as bools like their string forms. A param that
opts out of validation is no longer coerced, since its validator never ran.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate

Copy link
Copy Markdown
Member Author

@tenki-reviewer thanks, all three nitpicks are handled in 067814c060:

  • JSON int 1/0: fixed. coerce() now maps the integers the loose Boolean validator accepts too. Covered by the new int zero / int one provider cases.
  • skipValidation opt-out: fixed. Coercion now runs only inside the validated branch, so a param that skips validation keeps its raw value (testBooleanStringStaysAStringWhenValidationIsSkipped).
  • Resolving the validator twice: kept as is. It only happens for the boolean literals, the factory is the same pure call, and sharing the resolved instance would change the protected validate() signature, which breaks subclasses of the published package.

All three new tests fail without the fix and pass with it.

🤖 Addressed by Claude Code

@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR teaches the Utopia HTTP layer to coerce string query parameters to real booleans before a Boolean-validated param reaches the action, so ?total=false no longer arrives as the string "false". Tests in packages/http cover Http param resolution and Route behavior, and e2e bases assert the coerced behavior on real list endpoints.

Files Change
packages/http/src/Http.php Coerces string values to bool for Boolean-validated params before validation/dispatch.
packages/http/tests/HttpTest.php Unit tests for the coercion path across supplied values.
packages/http/tests/RouteTest.php Route-level tests locking the new param behavior.
tests/e2e/Services/Databases/DatabasesBase.php Asserts bool coercion on the Databases list total param.
tests/e2e/Services/Users/UsersBase.php Asserts bool coercion on the Users list total param.
packages/http/phpstan-baseline.neon Baseline refresh for the touched package.

Reviewed commit: 067814c

@abnegate
abnegate merged commit 3c2766c into main Oct 15, 2026
65 checks passed
@abnegate
abnegate deleted the qfix-total-param branch October 15, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant