Skip to content

fix(databases): return 400 when a row is too large for its index - #14374

Merged
HarshMN2345 merged 4 commits into
mainfrom
fix-pg-index-row-size
Oct 13, 2026
Merged

HarshMN2345 merged 4 commits into
mainfrom
fix-pg-index-row-size

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

What changed

Row create, update and upsert endpoints (single and bulk: Documents/Create.php, Update.php, Upsert.php, Bulk/Upsert.php, Bulk/Update.php) now catch Utopia\Database\Exception\Limit and return 400 with the database message, using the API's limit error (column_limit_exceeded for TablesDB, attribute_limit_exceeded for Collections). This matches what the transaction commit and increment/decrement already do.

On Postgres, a value too large for a B-tree index (SQLSTATE 54000) is already mapped to Limit by utopia-php/database, but these endpoints did not catch it, so it returned 500 general_unknown.

Verification

On the local Postgres stack: a TablesDB table with a varchar(700) column and a key index on it, then a row with 700 random 4-byte emoji (about 2,800 bytes).

Write path origin/main this branch
createRow 500 general_unknown 400 column_limit_exceeded
updateRow 500 400
upsertRow 500 400
createRows (one of two rows too large) 500, nothing written 400, nothing written
upsertRows 500 400
updateRows 500 400
transaction commit 400 attribute_limit_exceeded unchanged

The legacy Collections API createDocument returns 400 attribute_limit_exceeded. Pint and PHPStan pass on the changed files.

Fixes #14335

Row create, update and upsert, single and bulk, did not catch the
database Limit exception, so a value over the Postgres B-tree index row
size limit surfaced as a 500. Map it to the attribute/column limit
error, as the transaction commit and increment/decrement already do.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change maps the database layer's row-too-large-for-index limit exception to a client-facing 400 error on all document write paths: create, update, upsert, and their bulk variants. Each endpoint now catches the limit exception via the existing getLimitException() helper and responds with an appropriate error instead of leaking an internal failure.

Files Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/{Create,Update,Upsert}.php Catch the index-size limit exception and return a 400 error response.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/{Update,Upsert}.php Same limit-exception handling for the bulk write endpoints.

Reviewed commit: 6cef02c

@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The row and document create, update, and upsert handlers translate database limit exceptions into the API-specific 400 error for single and bulk writes. The new PostgreSQL E2E regression creates an indexed string field with a value exceeding the B-tree limit and checks all six write paths.

Latest changes: The latest commit adds a PostgreSQL E2E regression covering single and bulk create, update, and upsert responses for oversized indexed values.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 6
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php Maps bulk update limit exceptions to the API-specific limit error.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php Maps bulk upsert limit exceptions to the API-specific limit error.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Maps create limit exceptions to the API-specific limit error.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php Maps update limit exceptions to the API-specific limit error.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php Maps upsert limit exceptions to the API-specific limit error.
tests/e2e/Services/Databases/DatabasesBase.php Adds a PostgreSQL E2E regression for limit responses across six write paths.
✅ Fixed since the last review · 1
  • Add an E2E regression for the limit response · src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php:497

Reviewed the commits since 3cddb1d · 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 A · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 12, 2026 •

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 12, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-pg-index-row-size (after).

Metric Before After Change
🚀 Requests/sec 214.29 218.27 ⚪ +1.9%
⏱️ Latency P50 81.81 ms 79.6 ms ⚪ -2.7%
⏱️ Latency P95 182.26 ms 186.31 ms ⚪ +2.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 79.6 186.31 13,680 218.27 +4.05
Account 153.61 284.92 720 12.14 -6.94
TablesDB 75.98 135.77 7,440 121.9 -19.02
Storage 75.3 157.89 3,600 60.48 +2.97
Functions 118.38 225.35 1,920 32.91 +23.75

Top API waits (after)

API request Max wait (ms)
functions.create 409.36
account.prefs.update 395.11
storage.buckets.create 370.31
account.name.update 362.31
storage.files.create 320.36

Every row write path returns the limit error when a value does not fit
in its PostgreSQL B-tree index entry.

@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

It gated on _APP_DB_ADAPTER, and no adapter capability describes the
index entry size limit to gate on instead.
@HarshMN2345
HarshMN2345 merged commit 3244168 into main Oct 13, 2026
8 checks passed
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: a value too large for a column's index returns 500

2 participants