Skip to content

Uuid fromBytes throwing a error #464

@thauanvargas

Description

@thauanvargas

Describe the bug
I have a some queries that I think are a bit complex, with a lot of nested selects etc, I upgraded 0.7.0 to version 0.12.5 (Lumen upgrade too).

I started getting a error with whereIn and notIn, where I got arguments array must contain same amount of values, this was the error message in vsprintf function.

"message":"The arguments array must contain 5 items, 1 given","trace":"#0 C:\\Users\\thauan.vargas\\my-app\\vendor\\genealabs\\laravel-model-caching\\src\\CacheKey.php(128): vsprintf()

I proceed to change the CacheKey.php getInAndNotInClauses method's try/catch to throw the error and figured out the bytes of the uuid is not matching and got the error that's in the stacktrace. To fix the issue according to https://uuid.ramsey.dev/en/stable/database.html#storing-as-bytes to generate a Uuid it's using $uuid = Uuid::uuid4(); (version 4) so by changing the line where we get the subquery from bytes to $subquery = Uuid::uuid4()->fromBytes($subquery) seemed to work fine. I still wonder though if this is the right way and if so a fix to version for Lumen 9 could be created or if I should update something in my Application.

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

        $queryRed = $mainQuery()->whereNotIn('s.id', $queryGreen->select(DB::raw('distinct s.id')))
            ->whereNotIn('s.id', $queryYellow->select(DB::raw('distinct s.id')))
            ->where(DB::raw('DATE(i.date)'), '<=', $dates['red_date']);

Note: The query is much bigger then this, that's why I need Laravel Model Caching :D

Stack Trace

Ramsey\Uuid\Exception\InvalidArgumentException: $bytes string should contain 16 characters. in C:\Users\thauan.vargas\my-app\vendor\ramsey\uuid\src\Codec\StringCodec.php:88
Stack trace:
#0 C:\Users\thauan.vargas\my-app\vendor\ramsey\uuid\src\UuidFactory.php(269): Ramsey\Uuid\Codec\StringCodec->decodeBytes()
#1 C:\Users\thauan.vargas\my-app\vendor\ramsey\uuid\src\Uuid.php(466): Ramsey\Uuid\UuidFactory->fromBytes()
#2 C:\Users\thauan.vargas\my-app\vendor\genealabs\laravel-model-caching\src\CacheKey.php(115): Ramsey\Uuid\Uuid::fromBytes()
#3 C:\Users\thauan.vargas\my-app\vendor\genealabs\laravel-model-caching\src\CacheKey.php(335): GeneaLabs\LaravelModelCaching\CacheKey->getInAndNotInClauses()
#4 C:\Users\thauan.vargas\my-app\vendor\illuminate\collections\Traits\EnumeratesValues.php(734): GeneaLabs\LaravelModelCaching\CacheKey->GeneaLabs\LaravelModelCaching\{closure}()
#5 C:\Users\thauan.vargas\my-app\vendor\genealabs\laravel-model-caching\src\CacheKey.php(339): Illuminate\Support\Collection->reduce()
#6 C:\Users\thauan.vargas\my-app\vendor\genealabs\laravel-model-caching\src\CacheKey.php(49): GeneaLabs\LaravelModelCaching\CacheKey->getWhereClauses()
#7 C:\Users\thauan.vargas\my-app\vendor\genealabs\laravel-model-caching\src\Traits\Caching.php(182): GeneaLabs\LaravelModelCaching\CacheKey->make()
#8 C:\Users\thauan.vargas\my-app\vendor\genealabs\laravel-model-caching\src\Traits\Buildable.php(106): GeneaLabs\LaravelModelCaching\CachedBuilder->makeCacheKey()
#9 C:\Users\thauan.vargas\my-app\app\Services\I18nService.php(28): GeneaLabs\LaravelModelCaching\CachedBuilder->get()
#10 C:\Users\thauan.vargas\my-app\app\Http\Controllers\I18nController.php(14): App\Services\I18nService->getI18n()
#11 C:\Users\thauan.vargas\my-app\vendor\illuminate\container\BoundMethod.php(36): App\Http\Controllers\I18nController->getI18nByToken()
#12 C:\Users\thauan.vargas\my-app\vendor\illuminate\container\Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#13 C:\Users\thauan.vargas\my-app\vendor\illuminate\container\BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#14 C:\Users\thauan.vargas\my-app\vendor\illuminate\container\BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#15 C:\Users\thauan.vargas\my-app\vendor\illuminate\container\Container.php(661): Illuminate\Container\BoundMethod::call()
#16 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(391): Illuminate\Container\Container->call()
#17 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(357): Laravel\Lumen\Application->callControllerCallable()
#18 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(331): Laravel\Lumen\Application->callLumenController()
#19 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(284): Laravel\Lumen\Application->callControllerAction()
#20 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(264): Laravel\Lumen\Application->callActionOnArrayBasedRoute()
#21 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Routing\Pipeline.php(48): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()
#22 C:\Users\thauan.vargas\my-app\app\Http\Middleware\Authenticate.php(102): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
#23 C:\Users\thauan.vargas\my-app\vendor\illuminate\pipeline\Pipeline.php(180): App\Http\Middleware\Authenticate->handle()
#24 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Routing\Pipeline.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#25 C:\Users\thauan.vargas\my-app\vendor\illuminate\pipeline\Pipeline.php(116): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
#26 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(428): Illuminate\Pipeline\Pipeline->then()
#27 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(265): Laravel\Lumen\Application->sendThroughPipeline()
#28 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(171): Laravel\Lumen\Application->handleFoundRoute()
#29 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Routing\Pipeline.php(48): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()
#30 C:\Users\thauan.vargas\my-app\app\Http\Middleware\CorsMiddleware.php(54): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
#31 C:\Users\thauan.vargas\my-app\vendor\illuminate\pipeline\Pipeline.php(180): App\Http\Middleware\CorsMiddleware->handle()
#32 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Routing\Pipeline.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 C:\Users\thauan.vargas\my-app\vendor\illuminate\pipeline\Pipeline.php(116): Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing\{closure}()
#34 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(428): Illuminate\Pipeline\Pipeline->then()
#35 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(177): Laravel\Lumen\Application->sendThroughPipeline()
#36 C:\Users\thauan.vargas\my-app\vendor\laravel\lumen-framework\src\Concerns\RoutesRequests.php(112): Laravel\Lumen\Application->dispatch()
#37 C:\Users\thauan.vargas\my-app\public\index.php(28): Laravel\Lumen\Application->run()
#38 {main}  

Environment

  • PHP: 8.1
  • OS: Windows 11
  • Lumen: 9.1.6
  • Model Caching: 0.12.5

Additional context
I'm using lumen-framework and not a Laravel full project and on previous version (0.7.0) this was not occurring

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions