Skip to content

Commit 96ff1f3

Browse files
authored
pass batch parameters down to boto/dynamo (#308)
1 parent ce5a6cd commit 96ff1f3

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

pynamodb/models.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ def batch_get(cls, items, consistent_read=None, attributes_to_get=None):
260260
while items:
261261
if len(keys_to_get) == BATCH_GET_PAGE_LIMIT:
262262
while keys_to_get:
263-
page, unprocessed_keys = cls._batch_get_page(keys_to_get, consistent_read=None,
264-
attributes_to_get=None)
263+
page, unprocessed_keys = cls._batch_get_page(
264+
keys_to_get,
265+
consistent_read=consistent_read,
266+
attributes_to_get=attributes_to_get
267+
)
265268
for batch_item in page:
266269
yield cls.from_raw_data(batch_item)
267270
if unprocessed_keys:
@@ -282,7 +285,11 @@ def batch_get(cls, items, consistent_read=None, attributes_to_get=None):
282285
})
283286

284287
while keys_to_get:
285-
page, unprocessed_keys = cls._batch_get_page(keys_to_get, consistent_read=None, attributes_to_get=None)
288+
page, unprocessed_keys = cls._batch_get_page(
289+
keys_to_get,
290+
consistent_read=consistent_read,
291+
attributes_to_get=attributes_to_get
292+
)
286293
for batch_item in page:
287294
yield cls.from_raw_data(batch_item)
288295
if unprocessed_keys:
@@ -1209,7 +1216,7 @@ def _batch_get_page(cls, keys_to_get, consistent_read, attributes_to_get):
12091216
"""
12101217
log.debug("Fetching a BatchGetItem page")
12111218
data = cls._get_connection().batch_get_item(
1212-
keys_to_get, consistent_read, attributes_to_get
1219+
keys_to_get, consistent_read=consistent_read, attributes_to_get=attributes_to_get
12131220
)
12141221
cls._throttle.add_record(data.get(CONSUMED_CAPACITY))
12151222
item_data = data.get(RESPONSES).get(cls.Meta.table_name)

pynamodb/tests/test_model.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,33 @@ def test_batch_get(self):
23442344
}
23452345
self.assertEqual(params, req.call_args[0][1])
23462346

2347+
with patch(PATCH_METHOD) as req:
2348+
req.return_value = SIMPLE_BATCH_GET_ITEMS
2349+
item_keys = ['hash-{0}'.format(x) for x in range(10)]
2350+
for item in SimpleUserModel.batch_get(item_keys, attributes_to_get=['numbers']):
2351+
self.assertIsNotNone(item)
2352+
params = {
2353+
'ReturnConsumedCapacity': 'TOTAL',
2354+
'RequestItems': {
2355+
'SimpleModel': {
2356+
'Keys': [
2357+
{'user_name': {'S': 'hash-9'}},
2358+
{'user_name': {'S': 'hash-8'}},
2359+
{'user_name': {'S': 'hash-7'}},
2360+
{'user_name': {'S': 'hash-6'}},
2361+
{'user_name': {'S': 'hash-5'}},
2362+
{'user_name': {'S': 'hash-4'}},
2363+
{'user_name': {'S': 'hash-3'}},
2364+
{'user_name': {'S': 'hash-2'}},
2365+
{'user_name': {'S': 'hash-1'}},
2366+
{'user_name': {'S': 'hash-0'}}
2367+
],
2368+
'AttributesToGet': ['numbers']
2369+
}
2370+
}
2371+
}
2372+
self.assertEqual(params, req.call_args[0][1])
2373+
23472374
with patch(PATCH_METHOD) as req:
23482375
req.return_value = MODEL_TABLE_DATA
23492376
UserModel('foo', 'bar')

0 commit comments

Comments
 (0)