Repository navigation
fix(databases): see a batch's own writes when staging transaction operations - #14578
Conversation
…rations Staging operations checked a record's existence against the stored state plus the operations of earlier requests, and patched in only the creates of the same request. A delete, update, increment or decrement of a record a bulkCreate, bulkUpsert or upsert earlier in the same batch answered 404, and an operation on a record the same batch had deleted was accepted. The check now replays the batch's earlier operations on top of the stored log, the same way reads in the transaction see it, and answers row_not_found or table_not_found on TablesDB instead of the documents wording. Committing an upsert staged through createOperations also ignored the row ID it carried, so it created a row under a random ID; the commit now upserts under the staged ID, as create already did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟠 1 high 💬 Inline comments (1)
This PR makes operations that depend on documents created earlier in the same transaction work: staged operations are replayed as a pending overlay when validating later operations, replacing the removed dependants-tracking map, and commit-time upsert handling backfills the document ID into the staged data. Transaction not-found exceptions are centralized in shared helpers on the transactions
Reviewed commit: 80d2590 |
🟢 Tier S · Ready to merge
Transaction staging now replays earlier writes and deletes from the same request when checking record state, and uses surface-specific not-found errors. Commit handling applies staged creates and upserts under the operation’s record ID. Unit and E2E tests cover same-batch dependencies, delete behavior, and ID precedence for both creates and upserts. Latest changes: The newest commit extends the commit-ID E2E test to verify staged creates, like upserts, use the operation’s record ID when
📂 Walkthrough · 7
Merged |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
Adds read-your-writes for staged transaction operations via a pending-replay in TransactionState, backfills upsert $id at commit, and parameterizes transaction not-found exceptions, with new unit and e2e coverage.
Key findings
- 🟠 Commit upsert honors conflicting
data.$idover staged ID — Update.php:767
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…s record ID A staged create or upsert whose data also carried a different $id was written under that $id instead of the rowId or documentId the operation targets. The create and upsert endpoints always use the path ID; the commit now does too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A staged create whose data carries a different $id commits under the operation's record ID, as a staged upsert does; the test now proves both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…elete # Conflicts: # tests/unit/Databases/TransactionStateTest.php
What
Staging QA:
POST /v1/tablesdb/transactions/{T}/operationswith[{bulkCreate rowId bc2}, {delete bc2}](andupsertthendelete) answered 404 "Document with the requested ID 'bc2' could not be found". It said "Document" even on TablesDB.Why
Transactions/Operations/Create.phpchecked existence against the stored rows plus earlier requests' staged log. It patched in the current batch through a$dependantsmap that only recordedcreate, so a row written bybulkCreate,bulkUpsertorupsertearlier in the same batch looked missing. The same map also let acreate, delete, updatebatch through, because it never forgot the create.Fixing staging exposed a second bug at commit time: an
upsertstaged throughcreateOperationsnever set$idfromrowId/documentId, so commit created the row under a random ID. The upsert endpoint sets it;handleCreateOperationdoes too.Fix
TransactionState::getDocument()takes the request's pending operations and replays them after the stored log, the same replay reads in the transaction use. The staging check uses it, and$dependantsis gone.replay()now skips abulkCreateentry without$idinstead of indexing a missing key.row_not_found/table_not_foundon TablesDB, through newgetNotFoundException()/getParentNotFoundException()in the transactionsAction. That covers the staging check, the collection lookup, the permission pre-check and the commit'sNotFoundpath.handleUpsertOperationandhandleCreateOperationalways write under the operation'srowId/documentId, even whendata.$idnames a different one, as the create and upsert endpoints do.Tests
Unit tests, at the fixing layer (
tests/unit/Databases/TransactionStateTest.php):origin/maintestDocumentAnEarlierOperationOfTheSameRequestWritesExists(bulkCreate, bulkUpsert, upsert, create pending)testDocumentAnEarlierOperationOfTheSameRequestDeletesIsMissingAPI E2E (
tests/e2e/Services/Databases/Transactions/StagedDependants.php, inTransactionsBase), on Postgres plus Mongo for DocumentsDB:origin/maintestDeleteOfARecordAnEarlierOperationInTheSameBatchWrites: bulkCreate/bulkUpsert/upsert/create, each followed by delete in one batch, then commit and confirm each row is gonedocument_not_foundtestOperationOnARecordAnEarlierOperationInTheSameBatchDeletesIsNotFound: create, delete, update in one batch, expecting 404 with therow_not_foundwording on TablesDBrow_not_founddocument_not_foundtestCreateAndUpsertOperationsCommitUnderTheirRecordId: staged upserts of a new row, an existing row, and a row whosedata.$idnames another ID, plus a create whosedata.$idnames another ID; commit, then read eachFull
TablesDBTransactionsCustomServerTest,TablesDBTransactionsCustomClientTest,LegacyTransactionsCustomServerTest,DocumentsDBTransactionsCustomServerTestandTablesDBTransactionPermissionsCustomClientTestpass locally, excepttestCommitEventPayloadCarriesSurfaceIds. That test fails the same way onorigin/mainin my local stack (a webhook-delivery environment difference); CI covers it.🤖 Generated with Claude Code