Skip to content

fix: strip internal $collection from commit and bulk event payloads - #14216

Merged
HarshMN2345 merged 7 commits into
mainfrom
cursor/fix-db-create-event-database-id-a1ba
Oct 8, 2026
Merged

HarshMN2345 merged 7 commits into
mainfrom
cursor/fix-db-create-event-database-id-a1ba

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Row and document event payloads from bulk update, upsert, delete and transaction commit carried the internal $collection table name (for example database_1_collection_1), and $tenant on shared tables. Those paths never run processDocument(), so nothing removed them.

Both are now removed before the payload is queued for functions, webhooks and realtime, the same way processDocument() already removes $collection for single and bulk create.

$databaseId and the surface id ($tableId or $collectionId) were already present on every path, including commit since #13535.

Test Plan

  • testCommitEventPayloadCarriesSurfaceIds now also asserts $collection is absent. It fails on main and passes here (TablesDB and Legacy).
  • Checked bulk update, upsert and delete webhook payloads on a local stack for TablesDB and Legacy: before, $collection is present; after, the keys are $id, the columns, $sequence, $createdAt, $updatedAt, $permissions, $databaseId and the surface id.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • 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.

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The behavior changes are straightforward, but the bulk event path lacks automated coverage.

Removes internal $collection and $tenant fields from bulk document and transaction-commit event payloads. The transaction E2E test also checks that the commit payload omits $collection while retaining the surface identifiers.

Verdict New comments Fixed Still open
💬 Commented 1 0 0

[!NOTE]

Newer commits exist (`3928a1c`) and will be reviewed. This review is of `82d1ee7` and does not approve it.
Finding Where
🟡 Add coverage for bulk event payloads src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php:491
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php:491-492
**Add coverage for bulk event payloads**

The new E2E assertion covers transaction commits, but this removal also changes `triggerBulk()`, used by bulk update, upsert, and delete; those event payloads are not asserted in the E2E suite. A regression in this path could reintroduce either internal field without failing the new test, so please add an observable payload assertion for a bulk operation, including `$tenant`. 

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 3
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php Strips internal collection and tenant attributes before queuing bulk document events.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Strips internal collection and tenant attributes from transaction-commit event payloads.
tests/e2e/Services/Databases/Transactions/TransactionsBase.php Asserts that commit event payloads omit $collection.

Reviewed 82d1ee7 · 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 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/fix-db-create-event-database-id-a1ba (after).

Metric Before After Change
🚀 Requests/sec 157.53 193.58 🟢 +22.9%
⏱️ Latency P50 109.88 ms 88.74 ms 🟢 -19.2%
⏱️ Latency P95 257.67 ms 213.02 ms 🟢 -17.3%
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.74 213.02 12,426 193.58 -44.65
Account 171.28 369.96 654 10.85 -29.32
TablesDB 86.14 168.37 6,758 108.34 -32.16
Storage 80.76 175.53 3,270 54.02 -50.07
Functions 130.65 266.88 1,744 29.57 -46.85

Top API waits (after)

API request Max wait (ms)
account.prefs.update 579.94
account.name.update 517.99
functions.delete 420.68
functions.variables.update 414.58
tablesdb.rows.list 409.5

Create events for TablesDB were still carrying the legacy collection
shape. Publish the row or document model so the payload has $databaseId
and only the container id for the API that was called.
@cursor
cursor Bot force-pushed the cursor/fix-db-create-event-database-id-a1ba branch from 1aed62b to 257eda5 Compare October 7, 2026 10:03

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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

The response model already strips $tenant, and a stored document never
carries the other API's container id: writing one is rejected as an
unknown attribute.
Bulk update, upsert and delete never ran processDocument(), so their
event payloads carried the internal $collection table name, and
$tenant on shared tables. Remove both the same way processDocument()
removes $collection.
Committed rows and documents carried the internal $collection table
name, and $tenant on shared tables. Remove both before the payload is
built, keeping the hand-built $databaseId and surface id as before.
Single and bulk create payloads already carry $databaseId and the
surface id, and both tests pass without the fix, so they guard nothing.
@HarshMN2345 HarshMN2345 changed the title fix: include $databaseId on row and document create events fix: strip internal $collection from commit and bulk event payloads Oct 8, 2026
@HarshMN2345
HarshMN2345 marked this pull request as ready for review October 8, 2026 12:27
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Lock $tenant removal with an assertion like $collection (TransactionsBase.php:1966) — The new test assertion only pins $collection removal: $this->assertArrayNotHasKey('$collection', $delivery['data']) (tests/e2e/Services/Databases/Transactions/TransactionsBase.php:1966), but the commit-path code this test covers also strips $tenant (Transactions/Update.php:517).

The change removes leaked internal database metadata ($collection, $tenant) from the payloads published to events/webhooks/realtime when documents are written in bulk or committed as part of a transaction, and adds e2e coverage asserting the clean payload shape for $collection.

Files Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php Adds attribute-scrubbing of internal metadata before document event payloads are set in the bulk trigger path.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Applies the same payload scrub to documents emitted on the transaction commit path.
tests/e2e/Services/Databases/Transactions/TransactionsBase.php Extends the transactions e2e suite with an assertion that event payloads no longer contain the $collection key.

Reviewed commit: 82d1ee7

@HarshMN2345
HarshMN2345 merged commit f4c9901 into main Oct 8, 2026
4 checks passed

@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 · See the inline comments. Summary

src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php:491-492

Add coverage for bulk event payloads

The new E2E assertion covers transaction commits, but this removal also changes triggerBulk(), used by bulk update, upsert, and delete; those event payloads are not asserted in the E2E suite. A regression in this path could reintroduce either internal field without failing the new test, so please add an observable payload assertion for a bulk operation, including $tenant.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php
Line: 491-492

Comment:
**Add coverage for bulk event payloads**

The new E2E assertion covers transaction commits, but this removal also changes `triggerBulk()`, used by bulk update, upsert, and delete; those event payloads are not asserted in the E2E suite. A regression in this path could reintroduce either internal field without failing the new test, so please add an observable payload assertion for a bulk operation, including `$tenant`. 

---

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.

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