Skip to content

Commit 7e7e8b9

Browse files
scodejpinner-lyft
authored andcommitted
Improve documentation of batch writes. (pynamodb#396)
1 parent 3adf606 commit 7e7e8b9

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

pynamodb/models.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ class BatchWrite(ModelContextManager):
6161
"""
6262
def save(self, put_item):
6363
"""
64-
This adds `put_item` to the list of pending writes to be performed.
65-
Additionally, the a BatchWriteItem will be performed if the length of items
66-
reaches 25.
64+
This adds `put_item` to the list of pending operations to be performed.
65+
66+
If the list currently contains 25 items, which is the DynamoDB imposed
67+
limit on a BatchWriteItem call, one of two things will happen. If auto_commit
68+
is True, a BatchWriteItem operation will be sent with the already pending
69+
writes after which put_item is appended to the (now empty) list. If auto_commit
70+
is False, ValueError is raised to indicate additional items cannot be accepted
71+
due to the DynamoDB imposed limit.
6772
6873
:param put_item: Should be an instance of a `Model` to be written
6974
"""
@@ -76,8 +81,14 @@ def save(self, put_item):
7681

7782
def delete(self, del_item):
7883
"""
79-
This adds `del_item` to the list of pending deletes to be performed.
80-
If the list of items reaches 25, a BatchWriteItem will be called.
84+
This adds `del_item` to the list of pending operations to be performed.
85+
86+
If the list currently contains 25 items, which is the DynamoDB imposed
87+
limit on a BatchWriteItem call, one of two things will happen. If auto_commit
88+
is True, a BatchWriteItem operation will be sent with the already pending
89+
operations after which put_item is appended to the (now empty) list. If auto_commit
90+
is False, ValueError is raised to indicate additional items cannot be accepted
91+
due to the DynamoDB imposed limit.
8192
8293
:param del_item: Should be an instance of a `Model` to be deleted
8394
"""
@@ -294,9 +305,13 @@ def batch_get(cls, items, consistent_read=None, attributes_to_get=None):
294305
@classmethod
295306
def batch_write(cls, auto_commit=True):
296307
"""
297-
Returns a context manager for a batch operation'
308+
Returns a BatchWrite context manager for a batch operation.
298309
299-
:param auto_commit: Commits writes automatically if `True`
310+
:param auto_commit: If true, the context manager will commit writes incrementally
311+
as items are written to as necessary to honor item count limits
312+
in the DynamoDB API (see BatchWrite). Regardless of the value
313+
passed here, changes automatically commit on context exit
314+
(whether successful or not).
300315
"""
301316
return BatchWrite(cls, auto_commit=auto_commit)
302317

0 commit comments

Comments
 (0)