Skip to content

[12.x] Fix model serialization in queue jobs#58939

Merged
taylorotwell merged 2 commits into
laravel:12.xfrom
axlon:fix-model-identifier
Feb 20, 2026
Merged

[12.x] Fix model serialization in queue jobs#58939
taylorotwell merged 2 commits into
laravel:12.xfrom
axlon:fix-model-identifier

Conversation

@axlon

@axlon axlon commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

PR #58482 introduced morph map support for model identifiers, this PR addresses 2 bugs introduced by that PR.

  1. Deserialization always uses the morph map, even when not enabled. If a class happens to be registered as a morph alias, jobs using that model will be unable tk unserialize, e.g.:
        Relation::enforceMorphMap([
            'user' => User::class,
            'App\\Models\\User' => SomeOtherUser::class,
        ]);
  2. The above bug can be avoided by enabling morph maps (so opting in to the new feature), because then the model identifier will always use the morph map making serialization and deserialization be in sync again. However, you then run into the second issue; which is that collection deserialization was not updated to support morph maps and will then break

Edit: small note; ModelIdentifier::$class should probably be made protected/private on 13.x, consumers should not be using it directly and should instead be calling ModelIdentifier::getClass()

@taylorotwell taylorotwell merged commit 04b2984 into laravel:12.x Feb 20, 2026
72 checks passed
@axlon axlon deleted the fix-model-identifier branch February 21, 2026 18:57
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.

2 participants