-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
ShouldBeUnique Does Not Universally Prevent Duplicates #51798
Comments
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! |
As Taylor said we're tabling this one for now. |
@driesvints I'm nobody to question the maintenance team. But I did want to point out: (While I'm not intimately familiar with the internals) Taylor's comments makes it seem as though only undocumented dispatch methods are affected. But that's not the case. Using ShouldBeUnique as documented, with the documented Bus::chain, and Bus::batch methods does not guarantee uniqueness. The only way to guarantee a unique job is going through PendingDispatch, which Bus::chain and Bus::batch do not. I'm pretty confident, This is a broken feature. (10x, 11x, and 12x) |
Laravel Version
10.48.12 (although I believe relevant code has not changed in 11.x)
PHP Version
8.1.28
Database Driver & Version
Redis 7.2.5 (although issue should exist with other cache drivers)
Description
When dispatching jobs, the
ShouldBeUnique
behavior is only respected when dispatching through thePendingDispatch
class and theIlluminate\Console\Scheduling\Schedule
class (the latter fix was added in #39302). However, it is not respected when using theIlluminate\Bus\Dispatcher
class or individual queue drivers (Queue::push( ... )
, etc). This behavior can be confusing because depending on how you queue the job, it's easily possible to queue duplicates, despite the job implementingShouldBeUnique
I found a previous PR (#50381) that attempted to move the
ShouldBeUnique
check into theDispatcher
class. Although that still wouldn't guarantee uniqueness when usingQueue::push()
. I was also able to find some other issues which seem to indicate that people are generally expectingShouldBeUnique
to work universally:There's also a mention in the original PR for the
ShouldBeUnique
feature mentioning how this could possibly be moved into theenqueueUsing()
logic in theQueue
class? This seems like it would probably fix all of the above issuesFurther, the
Dispatcher
class and QueueenqueueUsing()
method already check other "expressive" interfaces likeShouldQueue
,ShouldQueueAfterCommit
, etc, so it seems reasonable to also checkShouldBeUnique
thereI would be willing to open a PR for this if desired. Was hesitant to do so as a similar PR (#50381) has already been closed
Steps To Reproduce
Create a job which implements
ShouldBeUnique
Confirm that
ShouldBeUnique
works correctly when usingPendingDispatch
. In tinkerConfirm that using
Queue::push(new UniqueJob())
,app(Dispatcher::class)->dispatch(new UniqueJob())
,Bus::dispatch(new UniqueJob())
do not work the same wayThe text was updated successfully, but these errors were encountered: