Skip to content

fix(databases): name the record, field and ID in increment and bulk write errors - #14582

Merged
abnegate merged 4 commits into
mainfrom
qfix-error-messages
Oct 16, 2026
Merged

abnegate merged 4 commits into
mainfrom
qfix-error-messages

Conversation

@abnegate

@abnegate abnegate commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

What

Staging QA found several error messages that were wrong or garbled:

Request Message on main
increment/decrement a missing row column_not_found: "Column with the requested key '%s' could not be found."
increment/decrement a missing column the same raw %s
increment past max / decrement past min tablesDB "count" has reached the maximum value of 5
committed increment of a non-numeric column tablesDB "label" is not a number
bulk create with a stored or repeated ID "Row with the requested ID '' already exists."
bulk upsert with a repeated ID "Row with the requested ID 'multiple' already exists."

Fix

  • Increment.php / Decrement.php. The library throws NotFound both for a missing document and for a missing attribute. On NotFound, the action now reads the row back with the caller's permissions:

    • Row missing or unreadable: row_not_found/document_not_found with the row ID.
    • Row readable: column_not_found/attribute_not_found with the column key.

    The library's Authorization refusal gets the same treatment: an unreadable row answers as missing, and a readable row the caller can't update answers user_unauthorized. Either way, a caller learns nothing about rows it can't read.

  • Bound and type messages name the field (Column "count" or Attribute "count") instead of getSDKNamespace(). That covers Increment, Decrement and the transaction commit path in Transactions/Update.php.

  • Bulk create and bulk upsert duplicates go through a new getBatchDuplicateException() in the documents Action. It names the ID the batch repeats, or else the first batch ID already stored (one findOne on the error path). If neither lookup finds an ID, it uses a generic message instead of printing ''.

Out of scope:

  • The stray " in the index-length message is in utopia-php/database (separate PR).
  • int64 max printed as ...808 is in packages/validators (separate PR).

Tests

The fixes are in the HTTP actions, so the E2E tests are the fixing-layer tests (tests/e2e/Services/Databases/ErrorMessages.php, used by DatabasesBase):

Test TablesDB main TablesDB this PR Legacy main Legacy this PR DocumentsDB this PR
testIncrementOfAMissingRecordNamesTheRecord ❌ column_not_found ✅ row_not_found, "Row with the requested ID 'missing' …" ❌ attribute_not_found ✅ ✅
testIncrementOfARowTheCallerCannotReadLooksLikeAMissingRow (client user, no read/update on the row; absent ID vs hidden row, missing and existing column, increment and decrement) ❌ column_not_found '%s' / 401 for the hidden row ✅ identical 404 row_not_found ❌ ✅ ✅ (existing column)
testIncrementOfAMissingFieldNamesTheField ❌ '%s' ✅ 'nope' ❌ '%s' ✅ skipped (no attributes)
testIncrementPastItsBoundNamesTheField ❌ tablesDB "count"… ✅ Column "count" has reached the maximum value of 5 / minimum value of 0 ❌ databases "count"… ✅ ✅
testCommittedIncrementOfANonNumericFieldNamesTheField ❌ tablesDB "label" is not a number ✅ Column "label" is not a number ❌ databases "label"… ✅ skipped
testBulkCreateOfAnExistingIdNamesTheId ❌ ID '' ✅ names the stored ID ❌ ✅ ✅
testBulkCreateOfARepeatedIdNamesTheId ❌ ID '' ✅ names the repeated ID ❌ ✅ ✅
testBulkUpsertOfARepeatedIdNamesTheId ❌ ID 'multiple' ✅ names the repeated ID ❌ 'multiple' ✅ ✅

Also passing locally: every increment, decrement, bulk and upsert test in the TablesDB, Legacy and DocumentsDB server suites, plus the full TablesDB and Legacy transaction suites. The one exception is testCommitEventPayloadCarriesSurfaceIds, which fails the same way on main in my local stack because of webhook delivery.

🤖 Generated with Claude Code

…rite errors

An increment or decrement that hit a missing row answered column_not_found,
and both a missing row and a missing column printed the raw "%s" because the
exception was thrown without params. The action now tells them apart by
reading the row back, and names the row ID or the column key.

The bound and not-a-number messages started with the SDK namespace
("tablesDB "n" ..."); they now name the field ("Column "n" ...").

A bulk create that repeated an ID, or reused a stored one, answered "Row with
the requested ID '' already exists", and a bulk upsert answered 'multiple'.
Both now name the repeated ID, or the first stored one.

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

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)


The change reworks error reporting so duplicate-ID, missing-document, missing-attribute, and counter min/max failures carry the offending documentId/attribute (or Row/Column nouns for the Tables surface) into the exception messages, with a shared getBatchDuplicateException() helper handling both in-batch and stored duplicate attribution for bulk upserts and creates. Increment, Decrement, and transaction commit paths gain a follow-up document probe to distinguish missing records from missing attributes, and e2e coverage lands in a new ErrorMessages trait wired into DatabasesBase.

Files Change
Documents/Action.php Adds getBatchDuplicateException() resolving duplicate attribution for batch writes
Create.php, Bulk/Upsert.php Route duplicate errors through the new helper with document-ID context
Attribute/Increment.php, Attribute/Decrement.php Disambiguate not-found causes and parameterize min/max limit messages
Transactions/Update.php Parameterize the commit-failure message with the offending attribute
ErrorMessages.php, DatabasesBase.php (e2e) New e2e suite asserting the SDK-visible error messages for both API surfaces

Reviewed commit: ce34e5c

@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.

@luxor-code-review luxor-code-review Bot 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.

This PR improves user-facing error messages across the Databases Documents/Tables APIs by adding contextual params to duplicate, not-found, and limit exceptions, and introduces a new e2e ErrorMessages suite covering those contracts.

Key findings

@ghost

ghost commented Oct 16, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes handle inaccessible rows without exposing their existence, and I found no actionable defects.

This pull request corrects database error messages for increment/decrement operations, transaction commits, and duplicate IDs in bulk writes. It distinguishes missing rows from missing fields, names the affected fields and IDs, and adds E2E coverage across the database API variants, including permission-hidden rows.

Latest changes: The newest commits handle authorization failures in increment/decrement requests and add E2E coverage verifying that rows the caller cannot read are reported like missing rows.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 8
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php Adds shared batch duplicate-ID resolution for repeated or already-stored IDs.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php Names missing rows or fields and identifies the field in bound and authorization errors.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php Names missing rows or fields and identifies the field in bound and authorization errors.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php Uses shared duplicate-ID handling for bulk upserts.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Uses shared duplicate-ID handling for bulk creates.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Names the field in committed increment type errors.
tests/e2e/Services/Databases/DatabasesBase.php Includes database error-message cases in the shared E2E suites.
tests/e2e/Services/Databases/ErrorMessages.php Covers increment/decrement errors, permission-hidden rows, and duplicate-ID messages.

Merged main (9066a1a); no changes to this PR's code since 3b5f9c9 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

ghost
ghost previously requested changes Oct 16, 2026

@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 B · 1 blocking finding to address. Summary

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → qfix-error-messages (after).

Metric Before After Change
🚀 Requests/sec 201.73 195.28 ⚪ -3.2%
⏱️ Latency P50 85.76 ms 88.18 ms ⚪ +2.8%
⏱️ Latency P95 199.22 ms 208.87 ms ⚪ +4.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 88.18 208.87 12,540 195.28 +9.66
Account 165.02 303.44 660 11.04 +18.42
TablesDB 82.7 158.3 6,820 108.56 +2.28
Storage 85.81 190.44 3,300 54.05 +1.24
Functions 132.22 256.89 1,760 29.51 +10.44

Top API waits (after)

API request Max wait (ms)
functions.variables.update 495.83
account.prefs.update 450.19
functions.create 428.85
storage.buckets.create 420.7
functions.variables.create 411.81

…s a missing row

Telling a missing row from a missing column read the row back without
permissions, so a caller learned whether a row it could not read existed:
row_not_found for an absent ID, column_not_found for a hidden row. A caller
that could not update a hidden row got user_unauthorized for it, also unlike
an absent ID.

The row is now read back with the caller's permissions, and a row it cannot
read answers row_not_found or document_not_found with the same message as an
absent one, for a missing column and for a refused update alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ghost
ghost dismissed their stale review October 16, 2026 08:36

The findings that requested changes are resolved. See the summary comment for what is still open.

@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

@abnegate
abnegate merged commit ffd1249 into main Oct 16, 2026
37 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.

1 participant