Skip to content

Variations attributes not preserved if object is saved in Django cache #68

@baxeico

Description

@baxeico

Hi,
I'm using django-stdimage version 2.0.6. Consider the following example:

class Photo(models.Model):
    image = StdImageField(upload_to='photos', variations={
        'thumbnail': (500, 500),
    })

In a view I retrieve a Photo object and I want to cache it using default Django in-memory cache.

from django.core.cache import caches

cache = caches['default']
today_photo = cache.get('today_photo')
if today_photo is None:
    # Photo object not found in cache
    # retrieve it with some query
    today_photo = Photo.objects.filter(...)
    cache.set('today_photo', today_photo, 300)
    # this correctly logs the url of the thumbnail
    logger.debug('today_photo thumbnail: %s' % today_photo.image.thumbnail)
else:
    # Photo object is taken from cache
    # this is a server error: 'StdImageFieldFile' object has no attribute 'thumbnail'
    logger.debug('today_photo thumbnail: %s' % today_photo.image.thumbnail)

When retrieved from cache, the image field "lost" the thumbnail attribute. Is it a limitation of what can be saved in django cache or is it an issue you can address?

Thank you very much for your work!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions