Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting an AttributeError when using validates decorator with AssertionError #28

Open
alexvermeulen opened this issue Sep 12, 2016 · 1 comment
Labels

Comments

@alexvermeulen
Copy link

When adding model field validation with sqlalchemy's @validates decorator as illustrated in the docs I get the error AttributeError: 'AssertionError' object has no attribute 'msg'. It seems sqlalchemy-jsonapi is trying to access the exception message through e.msg where it should be accessible through e directly. I'm assuming this change happened with Python 3?

@alexvermeulen alexvermeulen changed the title AttributeError when using validates decorator with AssertionError Getting an AttributeError when using validates decorator with AssertionError Sep 12, 2016
alexvermeulen pushed a commit to alexvermeulen/sqlalchemy-jsonapi that referenced this issue Sep 12, 2016
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
alexvermeulen pushed a commit to alexvermeulen/sqlalchemy-jsonapi that referenced this issue Sep 12, 2016
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
alexvermeulen pushed a commit to alexvermeulen/sqlalchemy-jsonapi that referenced this issue Sep 12, 2016
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
@Anderycks Anderycks added the bug label Feb 24, 2017
@Anderycks
Copy link
Collaborator

It's actually just bad code. Python 2 has e.message but neither Python 2 or 3 has a msg attribute. As I said in the PR, I think we can just raise the caught exception. It's kind of scary this doesn't get caught by the test coverage, which would seem to indicate our tests aren't very robust.

btw, I'm helping Colton get patches reviewed and landed. I just started helping out. Sorry this issue and patch have been sitting for awhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants