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

Fixed #24727 -- Prevented ClearableFileInput from masking exceptions on Python 2. #6143

Merged
merged 1 commit into from Feb 15, 2016
Merged

Fixed #24727 -- Prevented ClearableFileInput from masking exceptions on Python 2. #6143

merged 1 commit into from Feb 15, 2016

Conversation

berkerpeksag
Copy link
Contributor

@@ -372,7 +372,10 @@ def is_initial(self, value):
"""
Return whether value is considered to be initial value.
"""
return bool(value and hasattr(value, 'url'))
try:
return bool(value and getattr(value, 'url'))
Copy link
Member

Choose a reason for hiding this comment

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

For simplicity, my instinct would be to revert hasattr when dropping Python 2 support. If you agree, could you add a comment about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

(I also fixed typo in the commit message)

@timgraham timgraham changed the title Fixes #24727 -- Prevented ClearableFileInput from masking exceptions on Python 2 Fixed #24727 -- Prevented ClearableFileInput from masking exceptions on Python 2. Feb 15, 2016
try:
# TODO: switch back to use hasattr when Python 2 support is dropped
return bool(value and getattr(value, 'url'))
except AttributeError:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the try...except dance is not necessary here. I'll update it to bool(value and getattr(value, 'url', False)).

@timgraham timgraham merged commit 043383e into django:master Feb 15, 2016
@berkerpeksag berkerpeksag deleted the 24727-is-initial branch February 15, 2016 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants