matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.26k stars 276 forks source link

Thumbnail template tag does not err gracefully when file not found. #461

Open bingosabi opened 6 years ago

bingosabi commented 6 years ago

I have a page which displays ~300 thumbnails using the ImageKit thumbnail template tag, but when a single file is not found then the entire page explodes. I encounter this when moving a database from prod to development for testing before I deploy if I don't move all of the accompanying source images and their generated thumbnails.

The Django Template guidelines suggest that tags should err gracefully, as any exception which is raised / not captured will cause such a server error:

Thus, filter functions should avoid raising exceptions if there is a reasonable fallback value to return. In case of input that represents a clear bug in a template, raising an exception may still be better than silent failure which hides the bug.

IMO, this is low priority as there is a workaround (Ensure that database file values link to valid files on disk), but thought I'd at least open an issue as the template tag doesn't adhere to the Django guideline. (It's not a template bug... it's a data issue.)

vstoykov commented 6 years ago

This looks similar to this one #339. Actually not only with ImageKit if you have missing files and you try to get URL for them in templates it will crash in front of you. I know that is very bad user experience when for some missing file on the page the whole page is gone and you see 500 response.

We need to investigate it further to see how to improve the UX. If you have time and you are willing to came up with a PR I will be very glad.