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

[bug]: PHP Type error when normalising request options #3658

Closed
1 task done
aykutersoy opened this issue Sep 6, 2024 · 0 comments · Fixed by #3659
Closed
1 task done

[bug]: PHP Type error when normalising request options #3658

aykutersoy opened this issue Sep 6, 2024 · 0 comments · Fixed by #3659
Labels
bug Something isn't working

Comments

@aykutersoy
Copy link
Contributor

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.
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.

1 participant