Skip to content

fix(docker): set PHP precision to -1 so floats keep every digit - #14381

Merged
HarshMN2345 merged 2 commits into
mainfrom
fix-float-precision
Oct 23, 2026
Merged

HarshMN2345 merged 2 commits into
mainfrom
fix-float-precision

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What changed

  • The image sets PHP's precision to -1 (docker/php.ini, copied into conf.d). PDO converts a float to a string with this setting in two places: when a float is bound as a string on write, and when pdo_pgsql fetches a float8 under ATTR_STRINGIFY_FETCHES. At the default of 14 digits, both cut doubles short. With -1, PHP uses the shortest string that round-trips.
  • New e2e test testCreateDocumentFloatPrecision: it writes 1234567.123456789 to a float column and reads it back.

Tested

On the local Postgres stack, with a sidecar API container:

  • Without the ini, the row is stored as 1234567.1234568 and read back as that value. A row stored with all its digits also lists as 1234567.1234568, 0.3 and 1.7976931348623e+308. The new test fails: 1234567.1234568 is identical to 1234567.123456789.
  • With the ini, 1234567.123456789, 0.30000000000000004, 1.7976931348623157e+308 and the point [13.40495412345679, 52.52000812345678] are stored and returned exactly.
  • LegacyCustomServerTest with the ini: testCreateDocumentFloatPrecision, testInvalidDocumentStructure, testSpatialPointAttributes, testIncrementAttribute, testDecrementAttribute, testAttributeResponseModels and testCreateCollectionInlineNumericRange all pass.

Fixes #14220

PDO casts a float bound as a string, and a float8 that pdo_pgsql fetches
under ATTR_STRINGIFY_FETCHES, with PHP's precision setting. At the default
of 14 digits a float column stored 1234567.123456789 as 1234567.1234568,
and a stored double was read back cut to 14 digits as well. -1 uses the
shortest representation that round-trips.
@luxor-code-review

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

Copy link
Copy Markdown

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

🧹 Nitpicks (2) — 🟢 2 low
  • 🟢 Assert float attribute creation response in new test (DatabasesBase.php:3245) — In testCreateDocumentFloatPrecision the POST creating the float attribute discards its response and asserts nothing (tests/e2e/Services/Databases/DatabasesBase.php:3245).
  • 🟢 Float test hardcodes API-key auth, skipping getHeaders() (DatabasesBase.php:3257) — The new test hardcodes 'x-appwrite-key' in all four calls (tests/e2e/Services/Databases/DatabasesBase.php:3257), while sibling tests use array_merge([...], $this->getHeaders()).

This PR ships the image with precision = -1 via a copied php.ini so PHP serializes floats with full precision when binding them to the database, plus a Databases e2e test verifying a high-precision float survives a create/read round trip. Two low-severity test-hygiene issues were noted in the new test only.

Files Change
Dockerfile, docker/php.ini Adds a php.ini with precision = -1, copied into the image as zz-php.ini to preserve float precision in PDO float stringification.
tests/e2e/Services/Databases/DatabasesBase.php Adds testCreateDocumentFloatPrecision covering float attribute creation, a document write/read round trip, and precision-preserving assertions.

Reviewed commit: 2676a6f

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • 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.

@ghost

ghost commented Oct 12, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The Docker image now configures PHP with precision = -1 so float-to-string conversions retain round-trip precision. A database e2e test creates and fetches a document containing a high-precision float and checks the returned value.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
Dockerfile Copies the new PHP precision configuration into the image's PHP configuration directory.
docker/php.ini Sets PHP precision to -1.
tests/e2e/Services/Databases/DatabasesBase.php Adds an e2e test for creating and retrieving a high-precision float value.

Reviewed 2676a6f · 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

✨ Benchmark results

Comparing main (before) → fix-float-precision (after).

Metric Before After Change
🚀 Requests/sec 187.59 172.05 🔴 -8.3%
⏱️ Latency P50 92.6 ms 99.57 ms 🔴 +7.5%
⏱️ Latency P95 213.36 ms 234.31 ms 🔴 +9.8%
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 99.57 234.31 10,887 172.05 +20.95
Account 198.94 363.88 573 9.49 +15.07
TablesDB 95.35 169.1 5,921 95.74 +12.23
Storage 92.57 201.59 2,865 48.29 +13.89
Functions 149.29 282.61 1,528 26.35 +21.27

Top API waits (after)

API request Max wait (ms)
account.name.update 567.71
tablesdb.rows.delete 515.28
tokens.files.list 475.34
functions.delete 464.26
functions.create 437.49

@HarshMN2345
HarshMN2345 merged commit 66e93de into main Oct 23, 2026
66 checks passed
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix(docker): set PHP precision to -1 so floats keep every digit

(cherry picked from commit 66e93de)
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.

🐛 Bug Report: Postgres adapter truncates float columns to 14 digits

1 participant