-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Closed
Labels
Description
- Laravel Version: 8.21.0
- PHP Version: 8.0.0
- Database Driver & Version: MySQL
Description:
A recent pull on the framework has broken the php artisan queue:retry. I submitted a comment on the commit but decided to create this issue since this is reproducible.
Steps To Reproduce:
- Create a fresh project
composer create-project laravel/laravel test- Create database migrations
php artisan queue:table
php artisan migrate- Insert a new user into the users table with an email address.
INSERT INTO users SET name="test", email="[email protected]", password="";- Make sure
.envis using database as the queue driver:
QUEUE_CONNECTION=database
- Create a new notification that will fail (
app/Notifications/TestNotification.php)
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
class TestNotification extends Notification implements ShouldQueue
{
use Queueable;
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
throw new \RuntimeException('Purposely fail this notification to test queue:retry');
}
}- Insert the notification into queue by calling this anywhere from the code:
(\App\Models\User::find(1))->notify(new \App\Notifications\TestNotification());- Run the queue worker. The worker should fail.
php artisan queue:work- Retry the queue, and the problem arise:
php artisan queue:retry allErrorException
Attempt to read property "timestamp" on null
at vendor/laravel/framework/src/Illuminate/Queue/Console/RetryCommand.php:132
128▕
129▕ $instance = unserialize($payload['data']['command']);
130▕
131▕ if (is_object($instance) && method_exists($instance, 'retryUntil')) {
➜ 132▕ $payload['retryUntil'] = $instance->retryUntil()->timestamp;
133▕ }
134▕
135▕ return json_encode($payload);
136▕ }
+16 vendor frames
Reasoning:
As per my comment on the commit, the retryUntil() method in the class SendQueuedNotifications does not always return a Carbon object as expected in the RetryCommand. Suggest a fix is to check also if the retryUntil() is returning a Carbon object before accessing the timestamp field.