Skip to content

fix(databases): report a column changed mid-write as column not found - #14376

Merged
HarshMN2345 merged 6 commits into
mainfrom
fix-column-delete-not-found
Oct 13, 2026
Merged

HarshMN2345 merged 6 commits into
mainfrom
fix-column-delete-not-found

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

What changed

When a column is deleted (or renamed) while rows are being written, a writer that read the schema before the change still writes the old column (its default on create/upsert, its cached value on update). Postgres rejects the statement with 42703 (undefined column) and the database library raises NotFound('Attribute not found'):

  • createDocument / createRow caught every NotFoundException as a missing table and returned 404 table_not_found for a table that still exists.
  • updateDocument / updateRow, upsertDocument / upsertRow and bulk upsert didn't catch it and returned 500 general_unknown.

All four now catch it the same way and re-read the table document, the same check they run before the write:

  • table document gone: table_not_found / collection_not_found.
  • table document present: column_not_found (attribute_not_found on the Collections API), "The schema changed while this request was running. Please try again."

Bulk update only writes the columns it is sent and was not affected.

Verification

Local stack, Postgres, API on this branch in a separate container, worker from the shared stack. Table with integer k and varchar y (default: "d"), 4 writers sending only k and 2 readers, then DELETE …/columns/y mid-load.

Writers main this branch
create row 4 per round 404 table_not_found 404 column_not_found
update row 4 per round 500 general_unknown 404 column_not_found
upsert row 4 per round 500 general_unknown 404 column_not_found
bulk upsert 4 per round 500 general_unknown 404 column_not_found
bulk update no errors no errors

Postgres logs column "y" of relation … does not exist for the failing statements, and the API logs NotFound: Attribute not found for the 500s. One round of create through /v1/databases/…/documents returns 404 attribute_not_found. Deleting the table mid-load (create and upsert writers): every failed read and write is 404 table_not_found. Reads are unaffected throughout.

pint --test and phpstan analyse pass on the changed files.

Fixes #14336

A row write that read the table's schema before a column was deleted
or renamed fills in that column's default, and Postgres rejects the
insert with an undefined column. The database library raises that as
NotFound('Attribute not found'), which createRow reported as
table_not_found. Report it as column_not_found (attribute_not_found
on the Collections API) and keep table_not_found for a missing table.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Schema-race fix applied only to Create (Create.php:490) — The new handling that reports a column deleted or renamed mid-write as a retryable structure error exists only in Documents/Create.php (src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php:490-498).

The change refines the NotFoundException handling in the document-create action so a stale-schema race (column dropped or renamed mid-write) surfaces as a structure error with a retry-oriented message instead of the misleading parent-not-found error, for both the Collections API and TablesDB wording.

Files Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Catches NotFoundException with message Attribute not found and throws getStructureNotFoundException() with a retry-oriented message, for both Collections API and TablesDB wording.

Reviewed commit: 2230cef

@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Create, update, and upsert document/row handlers now recheck collection metadata after database NotFoundExceptions, returning a parent-not-found error when the collection is gone and a column/attribute-not-found error when it still exists. This covers create, update, single upsert, and bulk upsert writes. The schema-change error asks clients to retry.

Latest changes: The newest commits replace operation- and collection-specific schema-change text with one consistent retry-oriented message across all four handlers.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php Classifies write-time NotFound errors by rechecking whether the collection remains, and uses the shared schema-change retry message.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Classifies write-time NotFound errors by rechecking whether the collection remains, and uses the shared schema-change retry message.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php Classifies write-time NotFound errors by rechecking whether the collection remains, and uses the shared schema-change retry message.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php Classifies write-time NotFound errors by rechecking whether the collection remains, and uses the shared schema-change retry message.

Merged main (03331d8); no changes to this PR's code since f0c7f59 · 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

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-column-delete-not-found (after).

Metric Before After Change
🚀 Requests/sec 222.02 226.16 ⚪ +1.9%
⏱️ Latency P50 77.48 ms 76.15 ms ⚪ -1.7%
⏱️ Latency P95 177.29 ms 182.82 ms ⚪ +3.1%
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 76.15 182.82 14,022 226.16 +5.53
Account 153.69 280.58 738 12.27 +10.35
TablesDB 72.93 129.39 7,626 124.78 -4.84
Storage 70.81 147.73 3,690 62.43 -13.71
Functions 117.83 227.03 1,968 34.04 +13.52

Top API waits (after)

API request Max wait (ms)
account.name.update 392.5
functions.variables.create 384.85
functions.delete 371.93
functions.create 365.07
account.prefs.update 344.85

…le document

Match on the table document instead of the database library's
exception message: a NotFound from the insert is table_not_found only
when the table document is gone, and a changed column otherwise.
Update, upsert and bulk upsert let the database library's NotFound
escape as a 500 when a column was deleted while the write ran. Catch
it as createRow does: table_not_found when the table document is gone,
column_not_found otherwise.
…-found

# Conflicts:
#	src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php
#	src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php
#	src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php
@HarshMN2345
HarshMN2345 merged commit b509020 into main Oct 13, 2026
58 of 59 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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: Deleting a column under write load returns "table not found" to writers

2 participants