Changes between Initial Version and Version 2 of Ticket #24727
- Timestamp:
- Apr 29, 2015, 11:06:43 AM (10 years ago)
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 wedefined a FileSystemStorage subclass with a custom url() method that computed a reverse URL for them.1 I 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. 2 2 3 This morning I noticed that some files would not show up in ourFileField 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.3 This 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. 4 4 5 5 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: