Skip to content

Commit 394636c

Browse files
Fix fetching of AssertionError message for Python 3
Exceptions in Python 3 no longer contain a `msg` attribute. Instead the exception message is accessible from the exception object directly. In order to maintain Python 2 support, attempt to fetch the message from `e.msg` and use `str(e)` as a default if the attribtue does not exist. Fixes ColtonProvias#28
1 parent 223d144 commit 394636c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sqlalchemy_jsonapi/serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def patch_resource(self, session, json_data, api_type, obj_id):
906906
raise ValidationError(str(e.orig))
907907
except AssertionError as e:
908908
session.rollback()
909-
raise ValidationError(e.msg)
909+
raise ValidationError(getattr(e, 'msg', str(e))
910910
except TypeError as e:
911911
session.rollback()
912912
raise ValidationError('Incompatible data type')
@@ -1043,7 +1043,7 @@ def post_collection(self, session, data, api_type):
10431043
raise ValidationError(str(e.orig))
10441044
except AssertionError as e:
10451045
session.rollback()
1046-
raise ValidationError(e.msg)
1046+
raise ValidationError(getattr(e, 'msg', str(e)))
10471047
except TypeError as e:
10481048
session.rollback()
10491049
raise ValidationError('Incompatible data type')

0 commit comments

Comments
 (0)