easy-thumbnails
easy-thumbnails copied to clipboard
Attributes error
Hello I am using easy-thumbnails for a long time and never had problems. Right now I am using celery to generate images for ThumbnailerImageField. like so:
@app.task(name=u'Get image')
def get_image(article):
if article.image_url:
im = urllib2.urlopen(article.image_url)
if im.code == 200:
article.image.save(u'{}.jpg'.format(article.id), ContentFile(im.read()))
And everything works but I have a lot of errors in the log Attribute error in files.py line 615 in function get_source_cache in Thumbnailer class. Could not find exact error but added some checks and it works now:
def get_source_cache(self, create=False, update=False):
if hasattr(self, 'remote_source'):
if self.remote_source:
return None
if hasattr(self, '_source_cache') and not update:
if self._source_cache or not create:
return self._source_cache
storage = None
if hasattr(self, 'source_storage'):
storage = self.source_storage
thumbnail_check_cache_miss = None
if hasattr(self, 'thumbnail_check_cache_miss'):
thumbnail_check_cache_miss = self.thumbnail_check_cache_miss
update_modified = (update or create) and timezone.now()
self._source_cache = models.Source.objects.get_file(
create=create, update_modified=update_modified,
storage=storage, name=self.name,
check_cache_miss=thumbnail_check_cache_miss)
return self._source_cache
Having the exact same issue when saving a picture from a celery tasks:
entity.picture.save('picture.jpg', cf)
File "/Users/esquevin/Sites/Envs/rude/lib/python2.7/site-packages/easy_thumbnails/files.py", line 753, in save
**kwargs)
File "/Users/esquevin/Sites/Envs/rude/lib/python2.7/site-packages/easy_thumbnails/files.py", line 668, in save
self.get_source_cache(create=True, update=True)
File "/Users/esquevin/Sites/Envs/rude/lib/python2.7/site-packages/easy_thumbnails/files.py", line 616, in get_source_cache
if self.remote_source:
AttributeError: 'ThumbnailerImageFieldFile' object has no attribute 'remote_source'
Same problem here, everything work fine without celery but when using celery I get the same error, have you found any solution or workaround?
I don't remember ever finding a fix for this one… good luck
Thanks for the fast reply, for the moment I could use the solution suggested by kpacn by I want to try to avoid to edit the source files of the library. Thanks again
If somebody encounter the same problem I found this as a fast workaround. Instead of manually editing the library like in @kpacn example, it is possible to set null some parameters before calling save method.
As a result @kpacn example would be
@app.task(name=u'Get image')
def get_image(article):
if article.image_url:
im = urllib2.urlopen(article.image_url)
if im.code == 200:
article.image.remote_source = None
article.image.source_storage = None
article.image.cover_image.thumbnail_check_cache_miss = None
article.image.save(u'{}.jpg'.format(article.id), ContentFile(im.read()))
@kpacn solution is certainly better but as I said I do not want to manually edit the library on each installation.