Skip to content

[11.x] ShouldBeUnique Does Not Universally Prevent Duplicates #51859

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

Conversation

kellerjmrtn
Copy link

Re-targets #51833 to 11.x

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@kellerjmrtn kellerjmrtn marked this pull request as ready for review June 20, 2024 13:42
@driesvints driesvints linked an issue Jun 28, 2024 that may be closed by this pull request
@taylorotwell
Copy link
Member

Going to table this one for now as we don't document any other way of dispatching jobs anymore.

@rodrigopedra
Copy link
Contributor

@taylorotwell can we move the Illuminate\Contracts\Queue\ShouldBeUnique to Illuminate\Contracts\Foundation in 12.x? As PendingDispatch lives in Illuminate\Foundation\Bus?

Or at least add a note in the docs about this feature only being available through PendingDispatch?

At least that would communicate better, from the code perspective, that this feature isn't supported when using the Queue component outside of Laravel.

I was working on a non-Laravel app that uses the Queue component, and this behavior was tricky, and surprising, to find out.

Of course, ideally, it would be great if something like this PR to be added.

@kellerjmrtn
Copy link
Author

@taylorotwell Coming back around to this one. Though it's an edge case, it does seem like it's possible to queue duplicated unique jobs using only the recommended, documented methods, for example:

Bus::chain([
  new UniqueJob(),
  new SomeOtherJob(),
  new YetAnotherJob(),
])->dispatch(); // Adds a UniqueJob instance to the queue

// Then
UniqueJob::dispatch(); // Adds a second UniqueJob instance to the queue, since a lock was never acquired from the Bus::chain() call

Queue::push() and Bus::dispatch() are also documented here for use in tinker, and they have the same issue

Furthermore, after #55420 's recent updates to the Queue class, it feels like we should probably just add full ShouldBeUnique support to it. Especially given @rodrigopedra's point, that people are using the standalone illuminate/queue package, which contains ShouldBeUnique but does not provide an implementation enforcing it

Willing to create a new, up to date PR if desired

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.

ShouldBeUnique Does Not Universally Prevent Duplicates
3 participants