SmileyChris / easy-thumbnails

Easy thumbnails for Django
http://easy-thumbnails.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
1.39k stars 319 forks source link

ThumbnailerImageField's delete_thumbnails() does not delete anything #357

Open Eraldo opened 9 years ago

Eraldo commented 9 years ago

I have a model with an image field:

image = ThumbnailerImageField(upload_to='features', blank=True, resize_source=dict(size=(40, 40)))

When I am in the shell and do:

image.delete_thumbnails()

I get 0 as a return.. and no file deleted ..no matter if the image has created thumbnails or not. I expected to get 2 and removal of the thumbnail files -- with the example image and files listed blow.

The image and thumbnails are there and named like:

myimage.png
myimage.png.40x40_q85.png
myimage.png.80x80_q85.png

How can I remove them with image.delete_thumbnails() .. or am I doing something wrong?

Versions:

django==1.7.1
easy-thumbnails==2.2
Eraldo commented 9 years ago

If I manually create a thumbnail from the shell before..

image.save_thumbnail(f.image.get_thumbnail(thumbnail_options={'size':(100,100)}))

Then all of a sudden image.delete_thumbnails() works.. and deletes all of them! => Very strange!

What is going on?

andreav commented 9 years ago

Same here, did you find a solution? As additional informations:

Now i'm using a manage.py commad to wipe dbcache out, using some code like this:

        for p in Photo.objects.all():
            p.image.delete_thumbnails()

But this code does nothing.

While debugging I saw

ThumbnailerFieldFile.get_source_cache()

returning an empty _source_cache (due to create=False flag) but I do not understand that code.

Django==1.7.7 easy-thumbnails==2.2

THUMBNAIL_CHECK_CACHE_MISS = False

aslheyrr commented 9 years ago

@Eraldo Hi, did you find a solution? I have same problem

DrChai commented 8 years ago

this issue happened on my production server(Linux). The reason is due to different _storage_hash _id. when processing delete_thumbnails(), it will try to compare self.storage_hash(source) with its thumbnails.storage_hash: https://github.com/SmileyChris/easy-thumbnails/blob/master/easy_thumbnails/files.py#L704 However the result is negative. You may modified your default storage settings, which would be assigned to in a lazyobject: https://github.com/SmileyChris/easy-thumbnails/blob/714aa5f36894797ca6c980c9bc8cfa52a46156c1/easy_thumbnails/storage.py#L27 Later, when delete_thumbnails() calls get_storage_hash() in utils.py:

storage = storage._wrapped

storage is "buildin.object" not exactly storage name u expected.