Skip to content
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

Internal error assigning bool to property expiresAt #321

Closed
Nextra opened this issue Apr 30, 2022 · 3 comments · Fixed by #326
Closed

Internal error assigning bool to property expiresAt #321

Nextra opened this issue Apr 30, 2022 · 3 comments · Fixed by #326
Labels
bug Something isn't working

Comments

@Nextra
Copy link
Contributor

Nextra commented Apr 30, 2022

Description
Calling createKey or even just getKeys fails with an error where MeiliSearch cannot assign the internal expiresAt property a timestamp.

Abbreviated Log

local.ERROR: Cannot assign bool to property MeiliSearch\Endpoints\Keys::$expiresAt of type ?DateTime {"userId":1337,"exception":"[object] (TypeError(code: 0): Cannot assign bool to property MeiliSearch\\Endpoints\\Keys::$expiresAt of type ?DateTime at /var/www/html/vendor/meilisearch/meilisearch-php/src/Endpoints/Keys.php:46)
[stacktrace]
#0 /var/www/html/vendor/meilisearch/meilisearch-php/src/Endpoints/Keys.php(123): MeiliSearch\\Endpoints\\Keys->newInstance()
#1 /var/www/html/vendor/meilisearch/meilisearch-php/src/Endpoints/Delegates/HandlesKeys.php(28): MeiliSearch\\Endpoints\\Keys->create()
#2 /var/www/html/vendor/laravel/scout/src/Engines/MeiliSearchEngine.php(362): MeiliSearch\\Client->createKey()

Environment:

  • Meilisearch version: v0.27.0rc2
  • meilisearch-php version: v0.23.1
@alallema
Copy link
Contributor

alallema commented May 2, 2022

Hi @Nextra,
Thanks for raising this issue. I can't reproduce this bug. Can you provide a piece of code that didn't work?

@alallema alallema added the needs more info This issue needs a minimal complete and verifiable example label May 2, 2022
@Nextra
Copy link
Contributor Author

Nextra commented May 2, 2022

Laravel Tinker REPL:

>>> $client = app(MeiliSearch\Client::class)
=> MeiliSearch\Client {#3921}
>>> $key = $client->createKey(['description' => 'test', 'actions' => ['version'], 'indexes' => [], 'expiresAt' => Carbon\Carbon::now()->addDay()])
TypeError: Cannot assign bool to property MeiliSearch\Endpoints\Keys::$expiresAt of type ?DateTime
>>> $client->getKeys()
TypeError: Cannot assign bool to property MeiliSearch\Endpoints\Keys::$expiresAt of type ?DateTime
>>> collect($client->getRawKeys()['results'])->where('description', 'test')->first()
=> [
     "description" => "test",
     "key" => "hl8fkZip780f6a75a4f5bf3163447f065966b9906b5f9ad2fd4bf1883c5ab84d044cefcc",
     "actions" => [
       "version",
     ],
     "indexes" => [],
     "expiresAt" => "2022-05-03T09:32:50.753753056Z",
     "createdAt" => "2022-05-02T09:32:50.761166Z",
     "updatedAt" => "2022-05-02T09:32:50.761166Z",
   ]

@alallema alallema added needs investigation Needs to take time to understand the issue. and removed needs more info This issue needs a minimal complete and verifiable example labels May 5, 2022
@Nextra
Copy link
Contributor Author

Nextra commented May 11, 2022

Update:

The issue is not limited to the expiresAt timestamp, but can happen on all three timestamps any key contains. It is completely dependent on the precise moment a key is created/updated and how Meilisearch then decides to format the timestamp output.

At present, this library seems to be too strict on parsing the timestamps it receives, and can break at any moment. expiresAt is just the most likely one, since its particular format pattern is so restrictive.

Tinker:

>>> $client = app(MeiliSearch\Client::class)
=> MeiliSearch\Client {#3921}
>>> $keys = collect($client->getRawKeys()['results']); null
=> null
>>> $keys->whereNotNull('expiresAt')->filter(fn ($k) => date_create_from_format('Y-m-d\TH:i:s\Z', $k['expiresAt']) === false)->count()
=> 3518
>>> $keys->whereNotNull('expiresAt')->filter(fn ($k) => date_create_from_format('Y-m-d\TH:i:s\Z', $k['expiresAt']) === false)->first()['expiresAt']
=> "2022-05-12T06:53:39.128139Z"
>>> $keys->filter(fn ($k) => date_create_from_format('Y-m-d\TH:i:s.vu\Z', $k['createdAt']) === false)->count()
=> 1
>>> $keys->filter(fn ($k) => date_create_from_format('Y-m-d\TH:i:s.vu\Z', $k['createdAt']) === false)->first()['createdAt']
=> "2022-05-09T05:14:58.994Z"
>>> $keys->filter(fn ($k) => date_create_from_format('Y-m-d\TH:i:s.vu\Z', $k['updatedAt']) === false)->count()
=> 2
>>> $keys->filter(fn ($k) => date_create_from_format('Y-m-d\TH:i:s.vu\Z', $k['updatedAt']) === false)->first()['updatedAt']
=> "2022-05-11T04:16:15.397Z"

@bors bors bot closed this as completed in b3daf75 Jun 21, 2022
@brunoocasali brunoocasali added bug Something isn't working and removed needs investigation Needs to take time to understand the issue. labels Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants