[13.x] Restore missing model deletion for broadcast events - #61074
Conversation
| $this->afterCommit = property_exists($event, 'afterCommit') ? $event->afterCommit : null; | ||
| $this->maxExceptions = $this->getAttributeValue($event, MaxExceptions::class, 'maxExceptions'); | ||
| $this->deleteWhenMissingModels = $this->getAttributeValue($event, DeleteWhenMissingModels::class, 'deleteWhenMissingModels'); | ||
| $this->deleteWhenMissingModels = $this->getAttributeValue($event, DeleteWhenMissingModels::class, 'deleteWhenMissingModels') ?? true; |
There was a problem hiding this comment.
could be a B/C no?
This defaults to false mostly looking at examples like the below
framework/src/Illuminate/Queue/Queue.php
Line 184 in bd6b543
There was a problem hiding this comment.
Thanks for pointing this out. Generic queued jobs do default to false. However, BroadcastEvent appears intentionally different: Taylor changed its $deleteWhenMissingModels property to default to true in commit a21ad160, titled “delete broadcast events that are missing models by default.”
A later forward merge introduced the constructor assignment that replaces this class-specific default with null. This PR restores that intended default while preserving an explicit $deleteWhenMissingModels = false, which is also covered by the regression test.
888e0dd to
24f1638
Compare
When a queued broadcast event does not explicitly configure missing-model behavior,
BroadcastEventreplaces its default$deleteWhenMissingModelsvalue oftruewithnull.The queue payload consequently records
deleteWhenMissingModelsasfalse. If an Eloquent model serialized with the event is deleted before the queue worker processes it, the broadcast job fails with aModelNotFoundExceptioninstead of being quietly discarded.This PR preserves the existing
truedefault when the underlying event does not provide a value.Events that explicitly set
$deleteWhenMissingModelstofalsecontinue to opt out of this behavior.Regression tests have been added for both the default behavior and the explicit opt-out.