Skip to content

Commit 76868ba

Browse files
authored
Merge pull request #426 from algolia/fix/duplicate-synonym-during-copy-index-between-app
2 parents ce6d601 + 76b33fb commit 76868ba

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
# Release Notes
88

9+
## Unreleased
10+
11+
### Fixed
12+
- On `getVersion` param used by `search_index.get_settings` ([#426](https://github.com/algolia/algoliasearch-client-python/pull/426))
13+
914
## [v2.0.3](https://github.com/algolia/algoliasearch-client-python/compare/2.0.2...2.0.3)
1015

1116
### Fixed

algoliasearch/search_index.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ def get_objects(self, object_ids, request_options=None):
132132
request_options
133133
)
134134
# store attributesToRetrieve for use in each request
135-
attributes_to_retrieve = request_options.data.pop('attributesToRetrieve', None)
135+
attributes_to_retrieve = request_options.data.pop(
136+
'attributesToRetrieve', None)
136137

137138
requests = []
138139
for object_id in object_ids:
@@ -234,12 +235,16 @@ def set_settings(self, settings, request_options=None):
234235
def get_settings(self, request_options=None):
235236
# type: (Optional[Union[dict, RequestOptions]]) -> dict # noqa: E501
236237

237-
params = {'getVersion': 2}
238+
if request_options is None or isinstance(request_options, dict):
239+
request_options = RequestOptions.create(self._config,
240+
request_options)
241+
242+
request_options.query_parameters['getVersion'] = 2
238243

239244
raw_response = self._transporter.read(
240245
Verb.GET,
241246
endpoint('1/indexes/{}/settings', self._name),
242-
params,
247+
None,
243248
request_options
244249
)
245250

algoliasearch/search_index_async.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ def browse_rules_async(self, request_options=None):
8080
def get_settings_async(self, request_options=None): # type: ignore
8181
# type: (Optional[Union[dict, RequestOptions]]) -> dict
8282

83-
params = {'getVersion': 2}
83+
if request_options is None or isinstance(request_options, dict):
84+
request_options = RequestOptions.create(self._config,
85+
request_options)
86+
87+
request_options.query_parameters['getVersion'] = 2
8488

8589
raw_response = yield from self._transporter_async.read(
8690
Verb.GET,
8791
endpoint('1/indexes/{}/settings', self._name),
88-
params,
92+
None,
8993
request_options
9094
)
9195

tests/features/test_account_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def test_cross_app_copy_index(self):
4646
self.assertEqual(self.index2.get_rule('one'), rule)
4747

4848
# Assert synonyms got copied
49+
list_synonyms1 = [synonym for synonym in self.index.browse_synonyms()]
50+
list_synonyms2 = [synonym for synonym in self.index2.browse_synonyms()]
51+
52+
self.assertEqual(list_synonyms1, list_synonyms2)
53+
54+
# Assert synomys are the same
4955
self.assertEqual(self.index2.get_synonym('one'), synonym)
5056

5157
# Assert that copying again fails because index already exists

tests/unit/test_search_index.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,48 @@ def test_get_settings(self):
172172
'ignorePlurals': True,
173173
}
174174

175-
settings = self.index.get_settings({'foo': 'bar'})
175+
request_options = RequestOptions.create(self.config, {'foo': 'bar'})
176+
settings = self.index.get_settings(request_options)
176177

177178
self.transporter.read.assert_called_once_with(
178179
'GET',
179180
'1/indexes/index-name/settings',
180-
{'getVersion': 2}, # asserts version 2 it's used.
181-
{'foo': 'bar'}
181+
None,
182+
request_options
182183
)
183184

185+
self.assertEqual(request_options.query_parameters['getVersion'], 2)
186+
184187
self.assertEqual(settings, {
185188
'searchableAttributes': ['attr1', 'attr2'],
186189
'numericAttributesForFiltering': ['attr1', 'attr2'],
187190
'replicas': ['index1', 'index2'],
188191
'ignorePlurals': True,
189192
})
190193

194+
def test_get_settings_none_as_request_options(self):
195+
self.index.get_settings()
196+
197+
args = self.transporter.read.call_args[0]
198+
199+
self.assertEqual(args[3].query_parameters['getVersion'], 2)
200+
201+
def test_get_settings_dict_as_request_options(self):
202+
self.index.get_settings({'foo': 'bar'})
203+
204+
args = self.transporter.read.call_args[0]
205+
206+
self.assertEqual(args[3].query_parameters['getVersion'], 2)
207+
208+
def test_get_settings_with_request_options(self):
209+
request_options = RequestOptions.create(self.config, {'foo': 'bar'})
210+
211+
self.index.get_settings(request_options)
212+
213+
args = self.transporter.read.call_args[0]
214+
215+
self.assertEqual(args[3].query_parameters['getVersion'], 2)
216+
191217
def test_save_synonyms(self):
192218
# Test null response
193219
self.index.save_synonyms([]).wait()

0 commit comments

Comments
 (0)