ic-labs / django-icekit

GLAMkit is a next-generation Python CMS by the Interaction Consortium, designed especially for the cultural sector.
http://glamkit.com
MIT License
47 stars 11 forks source link

Save ICEkit Image dimensions to DB whenever they are recalculated #227

Closed jmurty closed 7 years ago

jmurty commented 7 years ago

For ICEkit Images override Django's default handling of image fields to ensure the image dimension data calculated for the field is always persisted to the DB, even when the Image is not saved (or intended to be saved) by the surrounding code.

This is a fix for a situation where we essentially have bad data in the DB for images, where they have been uploaded to the CMS but the dimensions were not properly persisted to the DB at this time.

Without this change, sites with no image dimensions in the Image DB records will – when an Image is accessed for read-only display – repeatedly download the image file, recalculate dimensions of the image, re-set the Image model's width & height field values, but then throw away all this work because the model instance isn't subsequently saved.

jmurty commented 7 years ago

As the test failures show, over-eager early saving of Image instances might be a bad idea.

cogat commented 7 years ago

If populating the data in a migration achieves the same thing without touching code, why not do that?