Skip to content

Conversation

@GalahadXVI
Copy link

This PR adds support for the $deleteWhenMissingModels property on queued notifications, allowing notifications to be silently discarded when their dependent models no longer exist.

Fixes #58025

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@GalahadXVI GalahadXVI marked this pull request as ready for review January 16, 2026 14:15

$shouldDelete = $reflectionClass->getDefaultProperties()['deleteWhenMissingModels']
?? count($reflectionClass->getAttributes(DeleteWhenMissingModels::class)) !== 0;
if (! $shouldDelete && $class === SendQueuedNotifications::class) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is all this code needed?

Copy link
Author

Choose a reason for hiding this comment

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

@taylorotwell

I think when we're in handleModelNotFound, the model couldn't be restored from the queue, so we only have the class name, not the actual job instance.

Reflection on SendQueuedNotifications just gives us the default value (false), not what was actually set from the notification. The payload's displayName is the only way to get back to the original notification class at that point.

Copy link
Author

@GalahadXVI GalahadXVI Jan 16, 2026

Choose a reason for hiding this comment

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

This was the smallest change I could make to get it working. Happy on any suggestions though!

(though, I'm still confused as to why it worked pre-laravel 12 without this change. I couldn't figure it out)

Edit: I just tried out of curiosity to see if Claude could figure out why it worked previously and here is what it came back with:

commit dc63a5d changed resolveName() to resolveQueuedJobClass() in Laravel 12. For notifications, resolveName() returned the notification class via displayName, which accidentally made $deleteWhenMissingModels work. The new method returns the actual job class (SendQueuedNotifications), which broke it.

Copy link
Contributor

@cosmastech cosmastech Jan 16, 2026

Choose a reason for hiding this comment

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

😆 I feel called out.

@taylorotwell taylorotwell marked this pull request as draft January 16, 2026 17:47
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.

$deleteWhenMissingModels is being ignored for notifications

3 participants