Skip to content

Omit relationship attributes from create and transaction commit event payloads - #14349

Merged
abnegate merged 3 commits into
mainfrom
fix/realtime-relationship-payloads
Oct 15, 2026
Merged

abnegate merged 3 commits into
mainfrom
fix/realtime-relationship-payloads

Conversation

@abnegate

Copy link
Copy Markdown
Member

What does this PR do?

Align create, bulk document events, and transaction commit event payloads with the existing update path.

Document and row update already pass relationship attribute keys as sensitive when calling setPayload, so related documents are not embedded in realtime/event payloads. Create never called setPayload (the shared shutdown hook copied the full response), and transaction commit re-read committed rows via getDocument then called setPayload without those keys.

This change:

  • Sets the create event payload the same way update does
  • Passes the same relationship keys from transaction commit
  • Applies the same handling in triggerBulk so bulk create/update/upsert stay consistent (those routes still reject collections with relationship attributes)

TablesDB, DocumentsDB, and VectorsDB create/commit actions inherit these paths.

Test Plan

Added realtime e2e coverage in RealtimeCustomClientTest:

  • testCreateRelationshipPayloadAlignsWithUpdate — create a document that sets a relationship and assert the create event payload includes the document fields but not the relationship attribute
  • testTransactionCommitRelationshipPayloadAlignsWithUpdate — commit a transaction that creates the same shape and assert the commit event payload matches update

Related PRs and Issues

  • None

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?
Open in Web Open in Cursor 

Pass relationship attribute keys as sensitive on document create,
bulk document events, and transaction commit so those paths match
the existing update payload handling.

Co-authored-by: Jake Barnby <[email protected]>
@luxor-code-review

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

Copy link
Copy Markdown

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

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Recompute relationship keys per transaction operation (Update.php:510) — In the transaction commit path, the relationship-key array_map/array_filter block runs inside the per-operation loop (Transactions/Update.php:510-516), re-scanning the same collection's attributes for every operation.

The PR closes a realtime payload-leak gap where single-document creates, bulk creates, and transaction commits sent nested related documents to websocket subscribers while other paths already redacted them.

Files Change
Documents/Action.php Derives relationship attribute keys from the collection and marks them sensitive in each bulk-create event payload
Documents/Create.php Sets the event payload explicitly from the response model with relationship keys flagged sensitive
Transactions/Update.php Applies the same per-operation relationship redaction on the transaction commit path
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Adds e2e coverage asserting realtime payloads exclude relationship data

Reviewed commit: 2d71b89

@ghost

ghost commented Oct 11, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new schema lookup uses the collection cache already populated for commit, and its attribute shape matches existing transaction relationship handling.

Create, bulk-document, and transaction-commit events now omit relationship attributes from their payloads, consistent with document and row updates. Realtime e2e coverage checks create and transaction-commit payloads for related documents.

Latest changes: The latest commit reads relationship keys from the fully loaded collection schema, since the metadata lookup used during commit omits attribute subqueries.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php Applies relationship-sensitive filtering to bulk document event payloads.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Sets create event payloads from the serialized response and filters relationship attributes.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php Filters relationship attributes from transaction commit event payloads using the loaded collection schema.
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Adds realtime coverage for relationship omission on create and transaction commit.

Merged main (939fa5e); no changes to this PR's code since 833472f · 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 11, 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 11, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/realtime-relationship-payloads (after).

Metric Before After Change
🚀 Requests/sec 198.48 220.72 🟢 +11.2%
⏱️ Latency P50 87.51 ms 78.99 ms 🟢 -9.7%
⏱️ Latency P95 199.25 ms 179.49 ms 🟢 -9.9%
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.99 179.49 13,680 220.72 -19.75
Account 145.28 269.32 720 12.16 -27.7
TablesDB 76.21 132.69 7,440 121.56 -26.27
Storage 73.1 155.18 3,600 61.05 -13.24
Functions 116.2 225.98 1,920 33.34 -20.77

Top API waits (after)

API request Max wait (ms)
account.name.update 478.9
account.prefs.update 423.61
functions.delete 419
functions.variables.update 365.2
functions.create 346.44

cursoragent and others added 2 commits October 11, 2026 20:41
Transaction commit event payloads looked up relationship attributes
on a metadata document that skips those subqueries. Use the
collection already loaded during commit so create/update/upsert
commit events match the update payload shape.

Co-authored-by: Jake Barnby <[email protected]>
@abnegate
abnegate merged commit a10d3fd into main Oct 15, 2026
35 checks passed
@abnegate
abnegate deleted the fix/realtime-relationship-payloads branch October 15, 2026 07:58
imtia33 pushed a commit to imtia33/appwrite that referenced this pull request Oct 15, 2026
…tionship payloads

appwrite#14349 filtered relationship attributes out of create and transaction
commit event payloads by comparing against Database::VAR_RELATIONSHIP.
utopia-php/database 8 removed the VAR_* constants in favour of the
ColumnType enum, so every document create, bulk event trigger and
transaction commit fataled with an undefined constant and returned 500,
and PHPStan reported three classConstant.notFound errors.

Compare against ColumnType::Relationship->value, the idiom the rest of
the module already uses. Stored _metadata attributes, Appwrite attribute
documents and the Collection returned by getCollection() all carry the
type as the string 'relationship' (Attribute::storedType), so the filter
matches in every path that reaches it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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.

2 participants