1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixes #24727 -- Prevented ClearableFileInput from masking exceptions on Python 2

This commit is contained in:
Antonio Garcia-Dominguez
2015-04-29 17:38:20 +02:00
committed by Tim Graham
parent 81f7651728
commit 5c412dd8a7
2 changed files with 27 additions and 0 deletions

View File

@@ -377,6 +377,14 @@ class ClearableFileInput(FileInput):
"""
Return whether value is considered to be initial value.
"""
# hasattr() masks exceptions on Python 2.
if six.PY2:
try:
getattr(value, 'url')
except AttributeError:
return False
else:
return bool(value)
return bool(value and hasattr(value, 'url'))
def get_template_substitution_values(self, value):