Skip to content

Commit

Permalink
Remove ModelContextManager class. (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinner-lyft committed Oct 8, 2020
1 parent e246ae6 commit 9d57373
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Other changes in this release:
* Add the attribute name to error messages when deserialization fails (#815)
* Add the table name to error messages for transactional operations (#835)
* Move ``pynamodb.connection.util.pythonic`` to ``pynamodb.util.snake_to_camel_case`` (#753)
* Remove ``ModelContextManager`` class (#861)

Contributors to this release:

Expand Down
16 changes: 5 additions & 11 deletions pynamodb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,17 @@
log.addHandler(logging.NullHandler())


class ModelContextManager(Generic[_T]):
class BatchWrite(Generic[_T]):
"""
A class for managing batch operations
A class for batch writes
"""

def __init__(self, model: Type[_T], auto_commit: bool = True):
self.model = model
self.auto_commit = auto_commit
self.max_operations = BATCH_WRITE_PAGE_LIMIT
self.pending_operations: List[Dict[str, Any]] = []
self.failed_operations: List[Any] = []

def __enter__(self):
return self


class BatchWrite(ModelContextManager, Generic[_T]):
"""
A class for batch writes
"""
def save(self, put_item: _T) -> None:
"""
This adds `put_item` to the list of pending operations to be performed.
Expand Down Expand Up @@ -104,6 +95,9 @@ def delete(self, del_item: _T) -> None:
self.commit()
self.pending_operations.append({"action": DELETE, "item": del_item})

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""
This ensures that all pending operations are committed when
Expand Down

0 comments on commit 9d57373

Please sign in to comment.