Skip to content

Scope transactions to the API they were created from - #14350

Merged
abnegate merged 17 commits into
mainfrom
fix/transactions-api-family
Oct 22, 2026
Merged

abnegate merged 17 commits into
mainfrom
fix/transactions-api-family

Conversation

@abnegate

Copy link
Copy Markdown
Member

What does this PR do?

Transaction list, get, update, delete, and operations used the shared transactions collection with no record of which API created the document. A transaction created through TablesDB (or the legacy Databases / DocumentsDB APIs) could be listed, fetched, committed, rolled back, or given operations through the VectorsDB routes, and the other way around.

This change records the creating API family on each transaction and filters every later route by the family of the path that was called.

  • New type attribute on the transactions collection (legacy, tablesdb, documentsdb, vectorsdb), set at create time from the calling route.
  • List adds the same type filter databases already use: TablesDB and the legacy Databases API serve both of those types (they are the same product either side of a rename). DocumentsDB and VectorsDB only return transactions they created.
  • Get, update, delete, operations, and document/row staging treat a type mismatch as not found.

Existing transactions without a type

Transactions created before this attribute existed have no stored type. They are treated as the legacy family:

  • Schema default is legacy.
  • V25 adds the attribute and index, then backfills null type values to legacy.
  • By-id lookups still treat an empty type as legacy.

That means existing in-flight transactions stay visible and usable on /v1/databases/transactions and /v1/tablesdb/transactions. They are not returned or resolved on DocumentsDB or VectorsDB.

type is an internal collection field and is not added to the public Transaction response model.

Test Plan

  • E2E TransactionsFamilyCustomServerTest: a transaction created through one family is not listed, gettable, updatable, deletable, or writable via operations on another family (except legacy ↔ TablesDB, which share a family). Same-family list/get/update/delete still succeed.
  • Existing transaction suites for legacy, TablesDB, DocumentsDB, and VectorsDB remain the same-family contract.

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? (No public model or SDK metadata change.)
Open in Web Open in Cursor 

Record the creating API family on the transaction document and filter
list, get, update, delete, and operations by that family. Existing
transactions without a type stay on the legacy / TablesDB family.

Co-authored-by: Jake Barnby <[email protected]>
@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/transactions-api-family (after).

Metric Before After Change
🚀 Requests/sec 217.72 220.89 ⚪ +1.5%
⏱️ Latency P50 77.73 ms 79.46 ms ⚪ +2.2%
⏱️ Latency P95 191.79 ms 179.17 ms 🟢 -6.6%
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 79.46 179.17 13,680 220.89 -12.61
Account 139.9 265.3 720 12.15 -12.17
TablesDB 79.31 149.5 7,440 121.86 +17.12
Storage 68.09 163.08 3,600 60.72 -22.62
Functions 107.79 198.71 1,920 33.12 -43.78

Top API waits (after)

API request Max wait (ms)
functions.create 421.53
account.prefs.update 408.42
account.name.update 395.74
storage.files.update 345.19
tablesdb.rows.create 343.32

cursoragent and others added 5 commits October 11, 2026 20:43
V25 now guards the transactions iterator so a partial project fixture
or an older install without that collection can still finish migrateCollections.

Co-authored-by: Jake Barnby <[email protected]>
Port the transactions type attribute and _key_type index onto main's
Attribute and Index schema builders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate
abnegate marked this pull request as ready for review October 22, 2026 00:48
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 List filter hides transactions whose type is still NULL — XList.php:69
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Backfill materializes all legacy transactions in memory (V25.php:243) — The V25 transactions backfill calls iterator_to_array($this->documentsIterator($id, [Query::isNull('type')])) (src/Appwrite/Migration/Version/V25.php:243), loading every transaction with a null type into memory before updating any.

Every transaction endpoint now scopes reads to its database family: a shared helper in Databases/Action.php injects a Query::equal('type', ...) filter and guards by-id lookups with an is-mismatch check that defaults missing types to legacy, so transactions created before this change stay visible.

Files Change
Transactions/* (Get, Update, Delete, Operations/Create, XList, Create) Apply family type filters and mismatch guards, returning TRANSACTION_NOT_FOUND for wrong-family transactions
Collections/Documents/* and Bulk/* (create/update/delete/upsert, increment/decrement) Attach document writes to the ambient transaction only when its family matches the caller
app/config/collections/projects.php, src/Appwrite/Migration/Version/V25.php Add the type string attribute and _key_type index, then backfill NULL-typed transactions to legacy
tests/e2e/.../TransactionsFamilyCustomServerTest.php New e2e coverage for family isolation on the transactions endpoints

Reviewed commit: 19f8a8c

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Transactions now record the API family that created them, and transaction routes plus staged document/row operations enforce that family boundary while allowing legacy and TablesDB to share transactions. The migration adds the schema and index, backfills older records as legacy, and the PR adds E2E and migration coverage.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 7
File Change
app/config/collections/projects.php Adds the internal transaction family field and its lookup index.
src/Appwrite/Migration/Version/V25.php Adds transaction type schema migration and legacy backfill.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php Defines allowed transaction families and missing-type compatibility checks.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/ Stores transaction family on creation and applies family filtering to transaction list and by-ID routes.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/ Rejects mismatched transactions in staged document and row operations, including reads.
tests/e2e/Services/Databases/Transactions/TransactionsFamilyCustomServerTest.php Exercises transaction visibility and cross-family operation behavior across API families.
tests/unit/Migration/Version/V25Test.php Covers legacy transaction type backfill.

Reviewed 867ea4c · 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 · See the inline comments. Summary

@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 adds a type discriminator (Databases vs TablesDB vs VectorsDB) to the transactions collection with family-scoped filters on all transactions endpoints, plus a V25 migration that adds the attribute/index and backfills legacy rows.

Key findings

  • 🟡 List filter hides transactions whose type is still NULL — XList.php:69

cursoragent and others added 2 commits October 22, 2026 05:20
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

@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

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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 A · Looks good to merge. Summary

Comment thread src/Appwrite/Migration/Version/V25.php Resolved
Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

List and get only need the transaction type to decide whether the id belongs to this API. Loading it under the caller roles turned another user's in-family id into not-found on list.

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

Keys still load the transaction without document ACL so a foreign-family id is not-found. A session that cannot read the transaction is left to the existing empty-list path.

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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 A · Looks good to merge. Summary

Comment thread src/Appwrite/Migration/Version/V25.php Resolved
Each page loads only the remaining untyped rows, so an update that sets type does not skip later rows the way an offset walk would.

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread src/Appwrite/Migration/Version/V25.php Resolved
…iled page

Advance with cursorAfter so a page of failed updates still continues
through the remaining untyped rows.

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

@abnegate
abnegate merged commit 3e24c7a into main Oct 22, 2026
69 checks passed
@abnegate
abnegate deleted the fix/transactions-api-family branch October 22, 2026 06:51
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.

3 participants