Skip to content

[5.8] 5.8.29 tagged today breaks queue deserializing with Model::newCollection()#29196

Merged
taylorotwell merged 2 commits into
laravel:5.8from
tw99:Fix-queue-restoring-custom-collections
Jul 17, 2019
Merged

[5.8] 5.8.29 tagged today breaks queue deserializing with Model::newCollection()#29196
taylorotwell merged 2 commits into
laravel:5.8from
tw99:Fix-queue-restoring-custom-collections

Conversation

@tw99

@tw99 tw99 commented Jul 16, 2019

Copy link
Copy Markdown
Contributor

This change pull request #29196 breaks queued jobs using SerializesModels that expect a custom collection. The above changes return an EloquentCollection when unserialized regardless of the model overriding newCollection.

Example:

<?php

namespace App\Jobs;

use App\Models\Collections\PostsCollection;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class DoSomethingToPosts extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    public $posts;

    public function __construct(PostsCollection $posts)
    {
        $this->posts = $posts;
    }

    public function handle()
    {
        // This object is now \Illuminate\Database\Eloquent\Collection,
        // not a PostsCollection instance.
        $this->posts;
    }
}

Thanks @derekmd for the tips on this PR

@tw99 tw99 force-pushed the Fix-queue-restoring-custom-collections branch 3 times, most recently from 0422925 to 130c5b7 Compare July 16, 2019 22:12
@tw99 tw99 force-pushed the Fix-queue-restoring-custom-collections branch from 130c5b7 to 4525df0 Compare July 16, 2019 22:15
@tw99 tw99 changed the title Fix queue jobs restoring custom collection Fix queue jobs restoring custom Eloquent collection Jul 16, 2019
@tw99 tw99 changed the title Fix queue jobs restoring custom Eloquent collection 5.8.29 tagged today breaks queue deserializing with Model::newCollection() Jul 16, 2019
@driesvints

Copy link
Copy Markdown
Member

Why aren’t we filtering the original collection instead? 🤔

@driesvints driesvints changed the title 5.8.29 tagged today breaks queue deserializing with Model::newCollection() [5.8] 5.8.29 tagged today breaks queue deserializing with Model::newCollection() Jul 17, 2019
@taylorotwell taylorotwell merged commit 1f74cc1 into laravel:5.8 Jul 17, 2019
@tw99 tw99 deleted the Fix-queue-restoring-custom-collections branch August 20, 2019 17:35
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