Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique jobs broken when using uniqueVia method #54293

Closed
DougSisk opened this issue Jan 21, 2025 · 3 comments
Closed

Unique jobs broken when using uniqueVia method #54293

DougSisk opened this issue Jan 21, 2025 · 3 comments

Comments

@DougSisk
Copy link
Contributor

Laravel Version

11.39.0

PHP Version

8.4.2

Database Driver & Version

No response

Description

This deals specifically with PR #54000.

This line broke my unit tests due to fact that uniqueVia() returns a Illuminate\Contracts\Cache\Repository contract. getName() is only on Illuminate\Cache\Repository, not the individual drivers.

Steps To Reproduce

Create a queue job class that implements ShouldBeUnique with a uniqueVia method that returns a Cache driver:

<?php

namespace App\Jobs;

use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Cache;

class TestJob implements ShouldBeUnique, ShouldQueue
{
    use Queueable;

    public function handle(): void
    {
        //
    }

    public function uniqueVia(): Repository
    {
        return Cache::driver('array');
    }
}
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@bgurney
Copy link

bgurney commented Jan 22, 2025

Could the currently protected method Illuminate\Cache\Repository::getName() just be made public to solve this?

@DougSisk
Copy link
Contributor Author

Just edited my PR to include that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants