From 13db52f730293331a7484c4ab4d08e4ea44d679b Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Mon, 5 Oct 2026 21:18:48 +0200 Subject: [PATCH] fix(scheduler): accept ScheduledJobManager jobs queued before the upgrade Jobs that v4.3.23 put in the queue have no type property. The promoted constructor property had no default, so these jobs failed with "must not be accessed before initialization" after the upgrade. - Declare type as a normal property with a null default --- app/Jobs/ScheduledJobManager.php | 10 +++++++++- .../ScheduledJobManagerLegacyPayloadTest.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/ScheduledJobManagerLegacyPayloadTest.php diff --git a/app/Jobs/ScheduledJobManager.php b/app/Jobs/ScheduledJobManager.php index 4c3beb97cd..c218a53652 100644 --- a/app/Jobs/ScheduledJobManager.php +++ b/app/Jobs/ScheduledJobManager.php @@ -64,15 +64,23 @@ class ScheduledJobManager implements ShouldQueue private int $skippedCount = 0; + /** + * One key of TYPES, or null for all types. + * + * Declared with a default instead of promoted, so jobs queued by older versions without this property still run. + */ + public ?string $type = null; + /** * @param string|null $type One key of TYPES, or null for all types. */ - public function __construct(public ?string $type = null) + public function __construct(?string $type = null) { if ($type !== null && ! array_key_exists($type, self::TYPES)) { throw new \InvalidArgumentException("Unknown scheduled job type [{$type}]."); } + $this->type = $type; $this->onQueue(crons_queue()); } diff --git a/tests/Unit/ScheduledJobManagerLegacyPayloadTest.php b/tests/Unit/ScheduledJobManagerLegacyPayloadTest.php new file mode 100644 index 0000000000..4aa846c684 --- /dev/null +++ b/tests/Unit/ScheduledJobManagerLegacyPayloadTest.php @@ -0,0 +1,18 @@ +middleware(); + + expect($job->type)->toBeNull() + ->and($middleware[0])->toBeInstanceOf(WithoutOverlapping::class) + ->and($middleware[0]->key)->toBe('scheduled-job-manager'); +});