Skip to content

Commit

Permalink
Fix exception message (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst authored Jan 27, 2023
1 parent adc1577 commit c835789
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
Release Notes
=============

v5.3.5
----------
* Fix message of some exceptions derived from :class:`~pynamodb.exceptions.PynamoDBException` (#1113).

Contributors to this release:

* @pauliokas


v5.3.4
----------
* Make serialization :code:`null_check=False` propagate to maps inside lists (#1128).
Expand Down
2 changes: 1 addition & 1 deletion pynamodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"""
__author__ = 'Jharrod LaFon'
__license__ = 'MIT'
__version__ = '5.3.4'
__version__ = '5.3.5'
4 changes: 3 additions & 1 deletion pynamodb/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@


class PynamoDBException(Exception):
msg: str

"""
A common exception class
"""
def __init__(self, msg: Optional[str] = None, cause: Optional[Exception] = None) -> None:
self.msg = msg
self.msg = msg if msg is not None else self.msg
self.cause = cause
super(PynamoDBException, self).__init__(self.msg)

Expand Down
9 changes: 8 additions & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from botocore.exceptions import ClientError

from pynamodb.exceptions import PutError
from pynamodb.exceptions import PynamoDBException, PutError


def test_get_cause_response_code():
Expand Down Expand Up @@ -40,3 +40,10 @@ def test_get_cause_response_message__no_message():
error = PutError()
assert error.cause_response_message is None


class PynamoDBTestError(PynamoDBException):
msg = "Test message"


def test_subclass_message_is_not_overwritten_with_none():
assert PynamoDBTestError().msg == "Test message"

0 comments on commit c835789

Please sign in to comment.