-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use str to get the exception message #3912
Conversation
0761a06
to
ae077e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
We do have some custom exception where we define a message
. Example:
What would happen in those cases?
@humitos if all the custom exceptions are calling their parent Exception with the message, everything is ok. |
Good. Can you check that all our custom exception are like that? |
These class don't override the These override the I found those grepping the project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of str()
may cause problems especially in Python 2. Are we sure that none of these exception messages can contain non-ASCII characters?
Also, I'm probably missing something, but why did use builtins.str
instead of just str
?
@berkerpeksag I take the I check for an exception with non-ascii characters, this is what a found
With the imported str an exception happens. So, are we fine just removing the import? |
Ah, so I think using future and their implicit imports to do this is a bit bad idea. Even without using its implicit conversation, it's possible to get a >>> e = Exception(u'ıçğü')
>>> str(e)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128) (Since Django and other libraries use unicode to store data internally, the chance of getting a unicode I'd be more conservative and don't do this until we get rid of Python 2, but of course this is just my opinion. If we decide to get this in, it would be nice to check if we reach 100% branch coverage (including adding tests for the |
Maybe put this for python 3 milestone is the best |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to see some tests here, it seems we're disregarding some of our use cases of exceptions here.
More specifically, exceptions that use message
.
I agree on holding off here until this either has tests or we're closer to python 3.
@@ -5,6 +5,7 @@ | |||
absolute_import, division, print_function, unicode_literals) | |||
|
|||
import logging | |||
from builtins import str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builtins
is third party import
We're targeting 3.6 swap in prod in the move to new host. I'll target this at 2.5 milestone for now. |
Are you referring to a code that uses At least an exception change the |
ae077e9
to
56ca14f
Compare
Rebased and updated, we could remove the |
Prod is 3.6 now, probably time to merge this! |
We are catching exceptions of type
Exception
, which no always have themessage
attribute (python3 at least).