Skip to content

Caching query with % character in value string #516

Open
@JkappenFlashpoint

Description

@JkappenFlashpoint

Describe the bug
Bug Description
This issue occurs when using GeneaLabs Laravel Model Caching with an Eloquent query that includes a whereIn condition containing percentage (%) symbols in string values. The error "Missing format specifier at end of string" is triggered by vsprintf in CacheKey.php, where the percentage symbol is mistakenly interpreted as a format specifier.

Possible Cause
The vsprintf function expects valid format specifiers (e.g., %s, %d), but a raw % in the query value is incorrectly processed, leading to a ValueError.

Suggested Fix
Escaping percentage symbols or modifying how vsprintf is used in GeneaLabs Model Caching could prevent this issue.

Eloquent Query
Please provide the complete eloquent query that caused the bug, for example:

  CachedModel::query()->whereIn('value', ['10%', '20%'])->get();

Stack Trace

[2025-03-26 13:34:55] local.ERROR: Missing format specifier at end of string {"exception":"[object] (ValueError(code: 0): Missing format specifier at end of string at vendor/genealabs/laravel-model-caching/src/CacheKey.php:157)
[stacktrace]
#0 vendor/genealabs/laravel-model-caching/src/CacheKey.php(157): vsprintf('A--10%', Array)
#1 vendor/genealabs/laravel-model-caching/src/CacheKey.php(378): GeneaLabs\\LaravelModelCaching\\CacheKey->getInAndNotInClauses(Array)
#2 vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(791): GeneaLabs\\LaravelModelCaching\\CacheKey->GeneaLabs\\LaravelModelCaching\\{closure}('-filter_id_=_26...', Array, 1)
#3 vendor/genealabs/laravel-model-caching/src/CacheKey.php(373): Illuminate\\Support\\Collection->reduce(Object(Closure))
#4 vendor/genealabs/laravel-model-caching/src/CacheKey.php(53): GeneaLabs\\LaravelModelCaching\\CacheKey->getWhereClauses()
#5 vendor/genealabs/laravel-model-caching/src/Traits/Caching.php(183): GeneaLabs\\LaravelModelCaching\\CacheKey->make(Array, NULL, '')
#6 vendor/genealabs/laravel-model-caching/src/Traits/Buildable.php(106): GeneaLabs\\LaravelModelCaching\\CachedBuilder->makeCacheKey(Array)

Environment

  • PHP: [8.2.0]
  • Laravel: [10.48.26]
  • Model Caching: [11.0.1]

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions