Commit db2ea82
`HookContext.previous` is documented "for update/delete", and `update()` has
bound it all along — `delete()` never did. `previous` was `undefined` in both
`beforeDelete` and `afterDelete` for every single-record delete, so a legal
delete-side condition (`previous.status == 'done'`) was unevaluable and, since
#4775, rejected the whole operation — through the generic branch, which reads
as an author typo when the engine was simply not binding the key.
#5038 inverted the asymmetry: a predicate bulk delete already binds each
doomed row's pre-image on its per-row `afterDelete`, so the single-record path
was strictly worse than the bulk one — the opposite of the #4800/#4862 ruling
that single and bulk mean the same thing.
`delete()` now reads the doomed row once, before `beforeDelete` fires, and
binds it for both phases. The gate is demand-driven like `update()`'s: a
delete-side hook in either phase, or a roll-up summary aggregating this
object. The roll-up path's own later pre-image fetch is folded into that same
read, so an object with both pays one read, not two — and it is now the raw
driver read `update()` already hands `recomputeSummaries`. A missing row
leaves `previous` unbound rather than fabricating `{}`/`null`, and a
`beforeDelete` hook that repoints or clears the target id re-reads or drops
the binding so a stale pre-image never rides into `afterDelete`.
The pin that hid this — `hook-condition-previous-scope.test.ts`'s
"a delete-shaped context evaluates `previous` against the pre-image" — built
`previous` by hand and asserted the wrapper read it, greenlighting behaviour
the engine never produced. Replaced with end-to-end cases that drive a real
`engine.delete()`: both phases receive the stored pre-image, a `previous.*`
condition evaluates instead of rejecting, declared-field materialisation and
no-leak hold on the delete side, the read happens exactly once for the two
phases, an object with no delete-side hook pays no read at all, and a missing
row leaves `previous` unbound.
Fixes #5272
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1f0e7cb commit db2ea82
3 files changed
Lines changed: 336 additions & 26 deletions
File tree
- .changeset
- packages/objectql/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5532 | 5532 | | |
5533 | 5533 | | |
5534 | 5534 | | |
| 5535 | + | |
| 5536 | + | |
| 5537 | + | |
| 5538 | + | |
| 5539 | + | |
| 5540 | + | |
| 5541 | + | |
| 5542 | + | |
| 5543 | + | |
| 5544 | + | |
| 5545 | + | |
| 5546 | + | |
| 5547 | + | |
| 5548 | + | |
| 5549 | + | |
| 5550 | + | |
| 5551 | + | |
| 5552 | + | |
| 5553 | + | |
| 5554 | + | |
| 5555 | + | |
| 5556 | + | |
| 5557 | + | |
| 5558 | + | |
| 5559 | + | |
| 5560 | + | |
| 5561 | + | |
| 5562 | + | |
| 5563 | + | |
| 5564 | + | |
| 5565 | + | |
| 5566 | + | |
| 5567 | + | |
| 5568 | + | |
| 5569 | + | |
| 5570 | + | |
| 5571 | + | |
| 5572 | + | |
| 5573 | + | |
| 5574 | + | |
| 5575 | + | |
| 5576 | + | |
| 5577 | + | |
| 5578 | + | |
| 5579 | + | |
| 5580 | + | |
| 5581 | + | |
| 5582 | + | |
| 5583 | + | |
| 5584 | + | |
| 5585 | + | |
| 5586 | + | |
| 5587 | + | |
| 5588 | + | |
| 5589 | + | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
| 5595 | + | |
| 5596 | + | |
| 5597 | + | |
| 5598 | + | |
| 5599 | + | |
| 5600 | + | |
| 5601 | + | |
5535 | 5602 | | |
| 5603 | + | |
| 5604 | + | |
| 5605 | + | |
| 5606 | + | |
| 5607 | + | |
| 5608 | + | |
| 5609 | + | |
| 5610 | + | |
| 5611 | + | |
| 5612 | + | |
| 5613 | + | |
| 5614 | + | |
| 5615 | + | |
| 5616 | + | |
5536 | 5617 | | |
5537 | 5618 | | |
5538 | 5619 | | |
| |||
5545 | 5626 | | |
5546 | 5627 | | |
5547 | 5628 | | |
5548 | | - | |
5549 | | - | |
5550 | | - | |
5551 | | - | |
5552 | | - | |
5553 | | - | |
5554 | | - | |
5555 | | - | |
5556 | | - | |
5557 | 5629 | | |
5558 | 5630 | | |
5559 | 5631 | | |
| |||
5607 | 5679 | | |
5608 | 5680 | | |
5609 | 5681 | | |
5610 | | - | |
5611 | | - | |
5612 | | - | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
| 5685 | + | |
| 5686 | + | |
| 5687 | + | |
| 5688 | + | |
5613 | 5689 | | |
5614 | 5690 | | |
5615 | 5691 | | |
| |||
0 commit comments