Changes between Initial Version and Version 2 of Ticket #24727


Ignore:
Timestamp:
Apr 29, 2015, 11:06:43 AM (10 years ago)
Author:
Antonio García-Domínguez
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24727

    • Property Has patch set
  • Ticket #24727 – Description

    initial v2  
    1 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.
     1I have a Python 2.7 site with some special requirements on how to link to uploaded files, so I defined a FileSystemStorage subclass with a custom url() method that computed a reverse URL for them.
    22
    3 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.
     3This morning I noticed that some files would not show up in a 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.
    44
    55I 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:
Back to Top