Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pynamodb/connection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,10 @@ def update_item(
try:
return self.dispatch(UPDATE_ITEM, operation_kwargs, settings)
except BOTOCORE_EXCEPTIONS as e:
raise UpdateError("Failed to update item: {}".format(e), e)
exc = UpdateError("Failed to update item: {}".format(e), e)
if exc.cause_response_code == "ConditionalCheckFailedException":
exc.__class__ = ConditionFailedUpdate
raise exc

def put_item(
self,
Expand Down Expand Up @@ -1079,7 +1082,10 @@ def put_item(
try:
return self.dispatch(PUT_ITEM, operation_kwargs, settings)
except BOTOCORE_EXCEPTIONS as e:
raise PutError("Failed to put item: {}".format(e), e)
exc = PutError("Failed to put item: {}".format(e), e)
if exc.cause_response_code == "ConditionalCheckFailedException":
exc.__class__ = ConditionFailedPut
raise exc

def _get_transact_operation_kwargs(
self,
Expand Down
14 changes: 14 additions & 0 deletions pynamodb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,27 @@ class PutError(PynamoDBConnectionError):
msg = "Error putting item"


class ConditionFailedPut(PutError):
"""
Raised when an item fails to be created due to condition
"""
msg = "Condition failed while putting item"


class UpdateError(PynamoDBConnectionError):
"""
Raised when an item fails to be updated
"""
msg = "Error updating item"


class ConditionFailedUpdate(UpdateError):
"""
Raised when an item fails to be updated due to condition
"""
msg = "Condition failed while updating item"


class GetError(PynamoDBConnectionError):
"""
Raised when an item fails to be retrieved
Expand Down