Skip to content

[13.x] Restore missing model deletion for broadcast events - #61074

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
Faiyajz:fix/broadcast-event-missing-model-default
Aug 6, 2026
Merged

[13.x] Restore missing model deletion for broadcast events#61074
taylorotwell merged 1 commit into
laravel:13.xfrom
Faiyajz:fix/broadcast-event-missing-model-default

Conversation

@Faiyajz

@Faiyajz Faiyajz commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

When a queued broadcast event does not explicitly configure missing-model behavior, BroadcastEvent replaces its default $deleteWhenMissingModels value of true with null.

The queue payload consequently records deleteWhenMissingModels as false. If an Eloquent model serialized with the event is deleted before the queue worker processes it, the broadcast job fails with a ModelNotFoundException instead of being quietly discarded.

This PR preserves the existing true default when the underlying event does not provide a value.

Events that explicitly set $deleteWhenMissingModels to false continue to opt out of this behavior.

Regression tests have been added for both the default behavior and the explicit opt-out.

$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;

@jackbayliss jackbayliss Aug 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be a B/C no?

This defaults to false mostly looking at examples like the below

'deleteWhenMissingModels' => $this->getAttributeValue($job, DeleteWhenMissingModels::class, 'deleteWhenMissingModels') ?? false,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Faiyajz
Faiyajz force-pushed the fix/broadcast-event-missing-model-default branch from 888e0dd to 24f1638 Compare August 6, 2026 12:07
@taylorotwell
taylorotwell merged commit a3b540a into laravel:13.x Aug 6, 2026
53 checks passed
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