Skip to content

Commit 759818f

Browse files
authored
Merge pull request #424 from msdinit/bugfix/apply-attributes-to-retrieve-bulk
Apply attributesToRetrieve parameter to each request created by index.get_objects
2 parents 9f2ca5e + dc8a1c8 commit 759818f

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

algoliasearch/search_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ def get_objects(self, object_ids, request_options=None):
131131
self._config,
132132
request_options
133133
)
134+
# store attributesToRetrieve for use in each request
135+
attributes_to_retrieve = request_options.data.pop('attributesToRetrieve', None)
134136

135137
requests = []
136138
for object_id in object_ids:
137139
request = {'indexName': self._name, 'objectID': str(object_id)}
138140

139-
if 'attributesToRetrieve' in request_options.data:
140-
request['attributesToRetrieve'] = request_options.data.pop(
141-
'attributesToRetrieve'
142-
)
141+
if attributes_to_retrieve:
142+
request['attributesToRetrieve'] = attributes_to_retrieve
143143

144144
requests.append(request)
145145

tests/unit/test_search_index.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,32 @@ def test_get_objects_with_attributes_to_retreive(self):
138138

139139
self.assertNotIn('attributesToRetrieve', request_options.data)
140140

141+
def test_get_objects_with_attributes_to_retreive_bulk(self):
142+
request_options = RequestOptions.create(self.config, {
143+
'attributesToRetrieve': ['firstname', 'lastname']
144+
})
145+
146+
requests = [{
147+
'indexName': 'index-name',
148+
'objectID': 'foo_id',
149+
'attributesToRetrieve': ['firstname', 'lastname']
150+
}, {
151+
'indexName': 'index-name',
152+
'objectID': 'bar_id',
153+
'attributesToRetrieve': ['firstname', 'lastname']
154+
}]
155+
156+
self.index.get_objects(['foo_id', 'bar_id'], request_options)
157+
158+
self.transporter.read.assert_called_once_with(
159+
'POST',
160+
'1/indexes/*/objects',
161+
{'requests': requests}, # asserts version 2 it's used.
162+
request_options
163+
)
164+
165+
self.assertNotIn('attributesToRetrieve', request_options.data)
166+
141167
def test_get_settings(self):
142168
self.transporter.read.return_value = {
143169
'attributesToIndex': ['attr1', 'attr2'],

0 commit comments

Comments
 (0)