Skip to content

🐛 Bug Report: getRow returns the pre-commit row after a transaction #14173

Closed

Description

@JoshiJoshiJoshi

👟 Reproduction steps

  1. Table with a string column status, create a row with status = "open".
  2. Create a transaction and stage {"action": "update", "rowId": <row>, "data": {"status": "done"}}.
  3. Start a few clients that keep calling GET /v1/tablesdb/{db}/tables/{table}/rows/{row} (any API node).
  4. Commit the transaction (PATCH /v1/tablesdb/transactions/{id}, commit: true) → 200.
  5. Stop the readers and call GET …/rows/{row} again.

Script used: 6 readers over two API nodes, commit after 0.3 s, then 20 reads 0.2 s after the commit returned; 30–40 rounds with a fresh row each.

👍 Expected behavior

After the commit returned 200, getRow returns status = "done".

👎 Actual Behavior

In some rounds every following getRow keeps returning the old row, while the database already has the new value:

rounds rounds with stale getRow stale after 5 s / 300 s
transaction commit (run 1) 30 2 (20/20 reads stale) 2 / –
transaction commit (run 2, with DB check) 40 5 (20/20 reads stale) 5 / 5 – in all 5 rounds listRows with equal $id returned done while getRow still returned open after 300 s
plain updateRow (same setup) 30 0 0

The stale entry stays until the next write to that row or until the document cache TTL (24 h, Database::TTL) expires.

In a real workload this broke a "status change + counter in one transaction" pattern: clients that re-read the row after staging (to verify it is still open) got the cached pre-commit row and counted twice.

Cause (as far as I can see):

  • Database::updateDocument() purges the document cache inside its transaction and again after commit "so readers cannot re-cache the pre-commit version" (Database.php L6551).
  • The transaction commit endpoint runs all staged operations inside one outer $dbForDatabases->withTransaction(...) (Transactions/Update.php L222). The inner withTransaction of updateDocument is nested (a SAVEPOINT), so its "after commit" purge runs before the real COMMIT.
  • A getRow arriving between that purge and the outer COMMIT misses the cache, reads the still-committed old row from Postgres and stores it (presumably the lease/generation check of saveWithLease passes because the read started after the purge; not verified in detail).
  • Nothing purges the touched rows after the outer commit, so the old version stays cached.

Plain updateRow is not affected because there the inner transaction is the outermost one.

🎲 Appwrite version

2.3.0 (utopia-php/database 7.3.11). utopia-php/database 7.4.0 / main (used by Appwrite main) have the same code.

💻 Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted Appwrite 2.3.0, Postgres adapter (PostgreSQL 18), Redis cache, two API nodes.

💡 Suggested fix

Purge the cache of every document touched by the commit after the outer withTransaction() returned (Appwrite already loops over the operations right after the commit for events), or let utopia defer "purge after commit" until the outermost transaction commits (e.g. collect keys while inTransaction > 1 and purge them in commitTransaction() at depth 0).

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Code of Conduct?

  • I have read the Code of Conduct

Activity

  1. added
    product / databases
    sdk / cli
    on Oct 6, 2026
  2. added 2 commits that reference this issue on Oct 7, 2026
    b103a78
    28e637f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasessdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions