Skip to content

Commit

Permalink
Fix fetching of AssertionError message for Python 3
Browse files Browse the repository at this point in the history
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 attribute does not exist.

Fixes ColtonProvias#28
  • Loading branch information
alex-vermeulen committed Sep 12, 2016
1 parent 223d144 commit 6ef1542
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlalchemy_jsonapi/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def patch_resource(self, session, json_data, api_type, obj_id):
raise ValidationError(str(e.orig))
except AssertionError as e:
session.rollback()
raise ValidationError(e.msg)
raise ValidationError(getattr(e, 'msg', str(e))
except TypeError as e:
session.rollback()
raise ValidationError('Incompatible data type')
Expand Down Expand Up @@ -1043,7 +1043,7 @@ def post_collection(self, session, data, api_type):
raise ValidationError(str(e.orig))
except AssertionError as e:
session.rollback()
raise ValidationError(e.msg)
raise ValidationError(getattr(e, 'msg', str(e)))
except TypeError as e:
session.rollback()
raise ValidationError('Incompatible data type')
Expand Down

0 comments on commit 6ef1542

Please sign in to comment.