-
Notifications
You must be signed in to change notification settings - Fork 26
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
We're passing readTimeout
, writeTimeout
, connectTimeout
(as int) as request options to SearchClient::search() method. When request options gets created in RequestOptionsFactory::create()
request options gets normalised in this line https://github.com/algolia/algoliasearch-client-php/blob/main/lib/RequestOptions/RequestOptionsFactory.php#L73 it's trying to array_merge
int and get below exception
TypeError: array_merge(): Argument #1 must be of type array, int given in file /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php on line 73
Stack trace:
1. TypeError->() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:73
2. array_merge() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:73
3. Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory->normalize() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:25
4. Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory->create() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:39
5. Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory->createBodyLess() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php:89
6. Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->sendRequest() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php:3114
7. Algolia\AlgoliaSearch\Api\SearchClient->sendRequest() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php:2336
8. Algolia\AlgoliaSearch\Api\SearchClient->search() /var/www/html/app/Search/Controller/SearchController.php:42
...
[REDACTED]
Language
PHP
Client
Search
Steps to reproduce
<?php
// File: hello_algolia.php
require_once realpath(__DIR__ . "/vendor/autoload.php");
use Algolia\AlgoliaSearch\Api\SearchClient;
$appID = "ALGOLIA_APPLICATION_ID";
// API key with `addObject` and `search` ACL
$apiKey = "ALGOLIA_API_KEY";
$indexName = "test-index";
$client = SearchClient::create($appID, $apiKey);
// Create a new record
$record = [
"objectID" => "object-1",
"name" => "test record",
];
// Add the record to an index
$saveResp = $client->saveObject($indexName, $record);
// Wait until indexing is done
$client->waitForTask($indexName, $saveResp['taskID']);
// Search for 'test'
$searchResponse = $client->search(
['requests' => [
['indexName' => $indexName, 'query' => 'test']
]],
[
'headers' => [
'X-Forwarded-For' => '127.0.01',
],
'readTimeout' => 1,
'writeTimeout' => 1,
'connectTimeout' => 1,
]
);
// Observe the exception
echo json_encode($searchResponse);
Relevant log output
TypeError: array_merge(): Argument #1 must be of type array, int given in file /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php on line 73
Stack trace:
1. TypeError->() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:73
2. array_merge() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:73
3. Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory->normalize() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:25
4. Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory->create() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php:39
5. Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory->createBodyLess() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php:89
6. Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper->sendRequest() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php:3114
7. Algolia\AlgoliaSearch\Api\SearchClient->sendRequest() /var/www/html/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php:2336
8. Algolia\AlgoliaSearch\Api\SearchClient->search() /var/www/html/app/Search/Controller/SearchController.php:42
...
[REDACTED]
Self-service
- I'd be willing to fix this bug myself.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working