laravel-model-caching
laravel-model-caching copied to clipboard
whereIn Subquery Error - "vsprintf(): Too few arguments"
Describe the bug
I'm experiencing a consistent error when using a subquery inside of a whereIn: vsprintf(): Too few arguments
in CacheKey.php:255
Have tried stripping down to the absolute minimum reproducible and it seems to happen on the second where
clause inside a whereIn subquery.
Eloquent Query
TaxBand::query()
->whereIn('id', function ($query) {
$query->select('abilities.entity_id')
->from('abilities')
->where('abilities.id', 1) // works fine up until here
->where('abilities.name', 'manage'); // fails here
})
->get();
Stack Trace See: https://flareapp.io/share/VP636Qq7#F77
Environment
- PHP: 7.4
- OS: MacOS
- Laravel: 8.13.0
- Model Caching: 0.11.0 and 0.11.1
Additional context Happy to provide anymore info, thank you!
Hi @joeyrush, thanks for submitting this issue! I will try to investigate this as soon as I can. I can't promise when this will be at this time, as we are in the middle of moving, but if it is something simple, I should be able to get it done within a week or two. You are more than welcome to also submit a PR with a failing test, and after that a PR that fixes the issue, if you have time.
Thanks again :)
Same here
+1 on it. I am getting the same on the whereIn.
Same for me
I see part of the issue here, I grabbed latest code / repo also but part of the issue is when the keys or some checking for keys use symbols...specifically the "%" which I think throws it off... Check my stack trace: I think that is the issue, I am not going to dive into it, but just off hand that data is a serial number I guess listed in my db so when im using the model caching it started to mess it up, So dove in that what I see.... #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'vsprintf(): Too...', '/u/sites/xfacts...', 157, Array) #1 /696969/genealabs/laravel-model-caching/src/CacheKey.php(157): vsprintf('%WK1KD002555_%W...', Array)
%WK1SD001755 is the value
a few like that in the string is my guess. weird wasnt previously an issue till the last one was added.
tracked it back to /src/CacheKey.php(368): GeneaLabs\LaravelModelCaching\CacheKey->getInAndNotInClauses(
Obviously worked around it with catching a throwable and not using cache for this one fail of the like 30k that dont fail
I'm experiencing the same problem, same place @axsweet, looks like someone fixed it on their on fork here: https://github.com/Nutickets/laravel-model-caching/commit/12feb91648565dca87389ace36c4604cb60bb0c2
@antonioribeiro would you be open to submitting a PR for this change, based on the commit you referenced from Nutickets? That would really help a lot. :)