algoliasearch-client-ruby icon indicating copy to clipboard operation
algoliasearch-client-ruby copied to clipboard

`get_objects` fails when passing in `attributesToRetrieve`

Open PFStein opened this issue 4 years ago • 1 comments

  • Algolia Client Version: algolia (2.2.2)
  • Language Version: ruby 2.6.5p114 (2019-10-01 revision 67812) [-darwin21]

Description

When passing in attributesToRetrieve to get_objects we receive an http error stating that attributesToRetrieve is an invalid key. We traced the issue back to the call made to the Algolia API here: https://github.com/algolia/algoliasearch-client-ruby/blob/5e7c715a596ac5e01064a16e9f46d3aaa825850b/lib/algolia/search_index.rb#L213

We tested that if we pass in request_options instead opts the call works as documented.

Steps To Reproduce

search_config = Algolia::Search::Config.new(
  application_id: 'app_id', api_key: 'api_key', symbolize_keys: false,
)
client = Algolia::Search::Client.new(search_config, { logger: Rails.logger })
index = client.init_index('my_index')
index.get_objects(['1'], { attributesToRetrieve: ["id"] })
# Fails with invalid key 'attributesToRetrieve'. Expected: appID, apiKey, requests (near 1:121)

PFStein avatar Jan 11 '22 17:01 PFStein

Additionally, it would be nice to use opts.dup on the parameter to avoid mutating a potentially frozen options hash.

liamgriffiths avatar Jan 11 '22 17:01 liamgriffiths