Skip to content

Commit 9d57373

Browse files
authored
Remove ModelContextManager class. (#861)
1 parent e246ae6 commit 9d57373

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

docs/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Other changes in this release:
3939
* Add the attribute name to error messages when deserialization fails (#815)
4040
* Add the table name to error messages for transactional operations (#835)
4141
* Move ``pynamodb.connection.util.pythonic`` to ``pynamodb.util.snake_to_camel_case`` (#753)
42+
* Remove ``ModelContextManager`` class (#861)
4243

4344
Contributors to this release:
4445

pynamodb/models.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,17 @@
4444
log.addHandler(logging.NullHandler())
4545

4646

47-
class ModelContextManager(Generic[_T]):
47+
class BatchWrite(Generic[_T]):
4848
"""
49-
A class for managing batch operations
49+
A class for batch writes
5050
"""
51-
5251
def __init__(self, model: Type[_T], auto_commit: bool = True):
5352
self.model = model
5453
self.auto_commit = auto_commit
5554
self.max_operations = BATCH_WRITE_PAGE_LIMIT
5655
self.pending_operations: List[Dict[str, Any]] = []
5756
self.failed_operations: List[Any] = []
5857

59-
def __enter__(self):
60-
return self
61-
62-
63-
class BatchWrite(ModelContextManager, Generic[_T]):
64-
"""
65-
A class for batch writes
66-
"""
6758
def save(self, put_item: _T) -> None:
6859
"""
6960
This adds `put_item` to the list of pending operations to be performed.
@@ -104,6 +95,9 @@ def delete(self, del_item: _T) -> None:
10495
self.commit()
10596
self.pending_operations.append({"action": DELETE, "item": del_item})
10697

98+
def __enter__(self):
99+
return self
100+
107101
def __exit__(self, exc_type, exc_val, exc_tb):
108102
"""
109103
This ensures that all pending operations are committed when

0 commit comments

Comments
 (0)