Skip to content

fix(databases): emit row events for bulk operations in a transaction - #14383

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix-transaction-bulk-events
Oct 28, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix-transaction-bulk-events

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What changed

Committing a transaction sent no events for its bulkCreate, bulkUpdate, bulkUpsert and bulkDelete operations, so webhooks, functions and realtime never saw those rows.

  • The bulk handlers in Transactions/Update.php collect the rows they write from their onNext callbacks. They keep a copy, because later operations change state documents in place.
  • After the commit each row gets its own create, update, upsert or delete event, with the same payload keys as the direct bulk endpoints. upsert matches upsertRows.

Verified

Local stack running this branch (TablesDB on Postgres), webhook on databases.<db>.tables.<table>.rows.*, 3 rows per operation:

Write path main this branch
createRows / updateRows / upsertRows / deleteRows 3 × create, update, upsert, delete same
transaction bulkCreate / bulkUpdate / bulkUpsert / bulkDelete none 3 × create, update, upsert, delete
transaction create + update create, update same
  • A realtime subscriber on the table channel got the same 12 transaction events. On main it got none.
  • One transaction with bulkCreate, bulkUpdate and bulkDelete on the same rows: the create payloads carry the rows as created, the update payloads the updated values.
  • e2e: TablesDBTransactionsCustomServerTest, TablesDBTransactionsCustomClientTest and LegacyTransactionsCustomServerTest pass.

Fixes #14219

The commit collected nothing for bulkCreate, bulkUpdate, bulkUpsert and
bulkDelete, so webhooks, functions and realtime never saw those rows.
Collect each bulk operation's rows from its onNext callback and send one
create, update, upsert or delete event per row after the commit, like
the direct bulk endpoints.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Cap bulk transaction events like direct bulk endpoints · Update.php:545–598 · unchanged line

// src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
545	                foreach ($documentsToTrigger as $doc) {
546	                    $doc->removeAttribute('$collection');
547	                    $doc->removeAttribute('$tenant');
548	
549	                    // Match the key set processDocument() gives every other row and document
550	                    // event: the synthetic $databaseId, plus whichever of $tableId or
551	                    // $collectionId belongs to the surface that was called.
552	                    $payload = $doc->getArrayCopy();
553	                    $payload['$databaseId'] = $database->getId();
554	                    $payload['$' . $groupId] = $collection->getId();
555	
556	                    $queueForEvents

The new event loop for bulk transaction operations emits one realtime, function, and webhook event per affected document with no batch cap (Transactions/Update.php:545-598), while the equivalent direct bulk endpoints cap collected documents at plan['databasesBatchSize'] ?? APP_LIMIT_DATABASE_BATCH (default 100) before triggering events (Bulk/Upsert.php:183). A single staged bulkCreate/bulkUpdate/bulkUpsert/bulkDelete touching N documents therefore enqueues N events synchronously inside the commit request. This diverges from the platform's event-flood contract and can flood the events/webhooks/functions queues and blow the commit request's memory and time limits for large bulk stages.


This PR extends the transaction commit endpoint so bulk operations staged in a transaction now emit per-document events (create/update/upsert/delete) after commit, mirroring the direct bulk endpoints, with clones of affected documents captured at operation time to protect event payloads from later state mutation.

Files Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Captures affected documents per bulk operation during commit, dedupes dependent-document rewrites, and emits events per document in the post-commit loop.

Reviewed commit: 1be8878

@ghost

ghost commented Oct 12, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

An earlier open minor finding still requests event assertions for the transaction bulk paths; this incremental change does not address it.

Transaction commits now retain per-operation row snapshots for bulk create, update, upsert, and delete, then emit one matching event per affected row after commit. The commit closure also shares the current attribute/change values with its outer exception handling so increment and decrement failures can be translated using the operation's details.

Latest changes: The newest change updates the commit closure captures to share currentAttribute and currentChange with the outer error handling and removes unused authorization-related captures.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php:520
**Add e2e coverage for transaction bulk events**

The transaction tests verify bulk operations' persisted results, but `testCommitEventPayloadCarriesSurfaceIds()` covers only a scalar create. Without event assertions for these new bulk paths, regressions in action names, row payloads, or snapshots across later operations can pass the suite unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 1
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Captures bulk row snapshots and emits per-row post-commit events; the latest change also shares increment/decrement error context with the outer handler.
⏳ Still open from earlier reviews · 1

Merged main (626c25b); no changes to this PR's code since 1de556d · 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

break;
case 'bulkCreate':
$eventAction = 'create';
$documentsToTrigger = $bulkDocuments[$operation->getId()];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add e2e coverage for transaction bulk events

The transaction tests verify bulk operations' persisted results, but testCommitEventPayloadCarriesSurfaceIds() covers only a scalar create. Without event assertions for these new bulk paths, regressions in action names, row payloads, or snapshots across later operations can pass the suite unnoticed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
Line: 520

Comment:
**Add e2e coverage for transaction bulk events**

The transaction tests verify bulk operations' persisted results, but `testCommitEventPayloadCarriesSurfaceIds()` covers only a scalar create. Without event assertions for these new bulk paths, regressions in action names, row payloads, or snapshots across later operations can pass the suite unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • 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-transaction-bulk-events (after).

Metric Before After Change
🚀 Requests/sec 217.04 218.39 ⚪ +0.6%
⏱️ Latency P50 81.2 ms 78.94 ms ⚪ -2.8%
⏱️ Latency P95 184.2 ms 185.58 ms ⚪ +0.7%
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 78.94 185.58 13,680 218.39 +1.38
Account 153.31 303.78 720 12.26 +38.14
TablesDB 76.37 145.48 7,440 121.78 +5.91
Storage 73.14 170.39 3,600 60.33 -2.98
Functions 110.68 214.93 1,920 32.99 -2.31

Top API waits (after)

API request Max wait (ms)
functions.create 510.17
account.name.update 438.49
tablesdb.rows.create 378
functions.delete 375.58
account.prefs.update 346.64

HarshMN2345 and others added 2 commits October 23, 2026 16:48
# Conflicts:
#	src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php
@HarshMN2345
HarshMN2345 merged commit a6874ac into main Oct 28, 2026
37 of 38 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: Bulk operations in a transaction trigger no events

2 participants