#24727: ClearableFileInput masks useful exceptions in is_initial()
----------------------------+--------------------
     Reporter:  bluezio     |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Forms       |    Version:  1.8
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  1           |      UI/UX:  0
----------------------------+--------------------
 I have a Python 2.7 site with some special requirements on how to link to
 uploaded files, so we defined a FileSystemStorage subclass with a custom
 url() method that computed a reverse URL for them.

 This morning I noticed that some files would not show up in our FileField
 with a ClearableFileInput widget after being uploaded through the Django
 admin app. After searching for a while, I found the issue: the
 hasattr(value, "url") call in ClearableFileInput.is_initial() was simply
 returning False for these files, masking an exception from the reverse()
 call of our custom url() method.

 I suggest changing ClearableFileInput.is_initial() so it will not mask
 useful exceptions. Instead of simply using hasattr, it should use a
 getattr call inside a try..except block and rethrow anything that is not
 an AttributeError. In fact, this is the new behavior of hasattr in Python
 3.2:

 https://docs.python.org/3.2/library/functions.html#hasattr

--
Ticket URL: <https://code.djangoproject.com/ticket/24727>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.895c0ac0447c688a53c54a71f58067ef%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to