-
Notifications
You must be signed in to change notification settings - Fork 11
Description
When trying to process an image that is of an unsupported format (like a Photoshop PSD file), img_to_fojb in utils.py crashes.
We should try to catch the exception and return something like NO_IMAGE instead of throwing a python error. This is specially important when there are a lot of images being processed (like in a script).
Note: the offending file was renamed as a JPG file, even though it's really a PSD file. I'm not sure what happens if you upload a PSD file with .psd extension.
See stack trace below:
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/init.py", line 438, in execute_manager
utility.execute()
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/init.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/base.py", line 191, in run_from_argv
self.execute(_args, *_options.dict)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/base.py", line 220, in execute
output = self.handle(_args, *_options)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/management/commands/rebuild_index.py", line 15, in handle
call_command('update_index', *_options)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/init.py", line 166, in call_command
return klass.execute(_args, *_defaults)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/base.py", line 220, in execute
output = self.handle(_args, *_options)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/management/commands/update_index.py", line 170, in handle
return super(Command, self).handle(_items, *_options)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/core/management/base.py", line 322, in handle
label_output = self.handle_label(label, *_options)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/management/commands/update_index.py", line 229, in handle_label
do_update(self.backend, index, qs, start, end, total, self.verbosity)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/management/commands/update_index.py", line 68, in do_update
backend.update(index, current_qs)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/backends/elasticsearch_backend.py", line 149, in update
prepped_data = index.full_prepare(obj)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/indexes.py", line 206, in full_prepare
self.prepared_data = self.prepare(obj)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/simplecart/meta_catalog/search_indexes.py", line 29, in prepare
data = super(BaseProductSearchIndex, self).prepare(obj)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/webcube/webcubecore/search_indexes.py", line 43, in prepare
return apply_boost(obj, super(WebcubeSearchMixin, self).prepare(obj))
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/indexes.py", line 197, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/fields.py", line 152, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/fields.py", line 73, in prepare
return self.prepare_template(obj)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/src/django-haystack/haystack/fields.py", line 130, in prepare_template
return t.render(Context({'object': obj}))
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 123, in render
return self._render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 117, in _render
return self.nodelist.render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/debug.py", line 73, in render_node
result = node.render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/loader_tags.py", line 127, in render
return compiled_parent._render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 117, in _render
return self.nodelist.render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/debug.py", line 73, in render_node
result = node.render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/loader_tags.py", line 64, in render
result = block.nodelist.render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 744, in render
bits.append(self.render_node(node, context))
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/debug.py", line 73, in render_node
result = node.render(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/defaulttags.py", line 306, in render
var = self.var.eval(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/defaulttags.py", line 851, in eval
return self.value.resolve(context, ignore_failures=True)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 510, in resolve
obj = self.var.resolve(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 653, in resolve
value = self._resolve_lookup(context)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/django/template/base.py", line 683, in _resolve_lookup
current = getattr(current, bit)
File "/Users/kam/dev/projects/webcube-littlegiraffe42/littlegiraffe/simplecart/meta_catalog/simpleproduct/models.py", line 176, in thumbnail
return self.original()['thumbnail']
File "/Users/kam/dev/virtualenvs/littlegiraffe42/lib/python2.7/site-packages/photoprocessor/fields.py", line 197, in getitem
self.data[key] = self._process_thumbnail(source_image, thumb_name, config)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/lib/python2.7/site-packages/photoprocessor/fields.py", line 212, in _process_thumbnail
thumb_fobj = ContentFile(img_to_fobj(img, info).read())
File "/Users/kam/dev/virtualenvs/littlegiraffe42/lib/python2.7/site-packages/photoprocessor/utils.py", line 20, in img_to_fobj
img.save(tmp, info['format'], **kwargs)
File "/Users/kam/dev/virtualenvs/littlegiraffe42/lib/python2.7/site-packages/PIL/Image.py", line 1429, in save
save_handler = SAVE[string.upper(format)] # unknown format
django.template.base.TemplateSyntaxError: Caught KeyError while rendering: 'PSD'