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

Fix fetching of AssertionError message for Python 3 #29

Conversation

alexvermeulen
Copy link

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.

I was going to add a test for this but I saw all the existing tests are currently commented out. I figured you were likely doing some refactoring and hadn't gotten to the tests yet. Perhaps you are already fixing this issue as part of your work as well. Regardless, I thought I'd throw up a PR in case it is useful to you.

Fixes #28

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 alexvermeulen force-pushed the ISSUE-28-attribute-error-on-validation branch from 6ef1542 to d62dc25 Compare September 12, 2016 00:52
Copy link
Collaborator

@Anderycks Anderycks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the best way to handle this. There's also a syntax error causing tests to fail.

There's no msg attribute on any Python exception, in 2 or 3. The best way to do this is simply raise the caught exception, i.e.

raise ValidationError(e)

As a side note, I don't think this code is executed in any tests, so there's no way to know if it's correct. I'd love if you could add some test coverage, but that's not required to get the patch landed. We do need to correctly raise the error and remove the syntax error to get this landed, though.

Thanks for submitting the patch!

@Anderycks
Copy link
Collaborator

Going to close this since it's not the right approach and there hasn't been any activity. We have issue #28 to remind us of the bug. Please feel free to reopen if you update the branch.

@Anderycks Anderycks closed this Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting an AttributeError when using validates decorator with AssertionError
3 participants