Skip to content

Commit c835789

Browse files
authored
Fix exception message (#1157)
1 parent adc1577 commit c835789

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

docs/release_notes.rst

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
Release Notes
44
=============
55

6+
v5.3.5
7+
----------
8+
* Fix message of some exceptions derived from :class:`~pynamodb.exceptions.PynamoDBException` (#1113).
9+
10+
Contributors to this release:
11+
12+
* @pauliokas
13+
14+
615
v5.3.4
716
----------
817
* Make serialization :code:`null_check=False` propagate to maps inside lists (#1128).

pynamodb/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
"""
88
__author__ = 'Jharrod LaFon'
99
__license__ = 'MIT'
10-
__version__ = '5.3.4'
10+
__version__ = '5.3.5'

pynamodb/exceptions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99

1010
class PynamoDBException(Exception):
11+
msg: str
12+
1113
"""
1214
A common exception class
1315
"""
1416
def __init__(self, msg: Optional[str] = None, cause: Optional[Exception] = None) -> None:
15-
self.msg = msg
17+
self.msg = msg if msg is not None else self.msg
1618
self.cause = cause
1719
super(PynamoDBException, self).__init__(self.msg)
1820

tests/test_exceptions.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from botocore.exceptions import ClientError
22

3-
from pynamodb.exceptions import PutError
3+
from pynamodb.exceptions import PynamoDBException, PutError
44

55

66
def test_get_cause_response_code():
@@ -40,3 +40,10 @@ def test_get_cause_response_message__no_message():
4040
error = PutError()
4141
assert error.cause_response_message is None
4242

43+
44+
class PynamoDBTestError(PynamoDBException):
45+
msg = "Test message"
46+
47+
48+
def test_subclass_message_is_not_overwritten_with_none():
49+
assert PynamoDBTestError().msg == "Test message"

0 commit comments

Comments
 (0)