django-imagekit: TypeError: 'ImageCacheFile' object is not subscriptable
Hi
I have gotten this error bellow, But It got fixed reloading (weird)
Stack: Ubuntu 14.04 python 3.4 django 1.8.16
Error:
Traceback (most recent call last):
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 819, in _resolve_lookup
current = current[bit]
TypeError: 'ImageCacheFile' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/inmoduran/inmoduran/landing/views.py", line 263, in property
'description': piso.pub_name(),
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/shortcuts.py", line 67, in render
template_name, context, request=request, using=using)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/loader.py", line 99, in render_to_string
return template.render(context, request)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 210, in render
return self._render(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 202, in _render
return self.nodelist.render(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 905, in render
bit = self.render_node(node, context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 919, in render_node
return node.render(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/defaulttags.py", line 224, in render
nodelist.append(node.render(context))
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 959, in render
output = self.filter_expression.resolve(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 648, in resolve
obj = self.var.resolve(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 789, in resolve
value = self._resolve_lookup(context)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/template/base.py", line 827, in _resolve_lookup
current = getattr(current, bit)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/__init__.py", line 84, in url
return self._storage_attr('url')
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/__init__.py", line 74, in _storage_attr
existence_required.send(sender=self, file=self)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/django/dispatch/dispatcher.py", line 189, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/registry.py", line 53, in existence_required_receiver
self._receive(file, 'on_existence_required')
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/registry.py", line 61, in _receive
call_strategy_method(file, callback)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/utils.py", line 151, in call_strategy_method
fn(file)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/strategies.py", line 15, in on_existence_required
file.generate()
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/__init__.py", line 93, in generate
self.cachefile_backend.generate(self, force)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/backends.py", line 109, in generate
self.generate_now(file, force=force)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/backends.py", line 96, in generate_now
file._generate()
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/cachefiles/__init__.py", line 97, in _generate
content = generate(self.generator)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/utils.py", line 134, in generate
content = generator.generate()
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/imagekit/specs/__init__.py", line 149, in generate
img = open_image(self.source)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/pilkit/utils.py", line 22, in open_image
return Image.open(target)
File "/home/inmoduran/inmoduran/env2/lib/python3.4/site-packages/PIL/Image.py", line 2286, in open
% (filename if filename else fp))
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16
@just-paja your exception is different. Your exception is
ValueError: I/O operation on closed file.
Which is more close to #391.The original issue title incorrectly points the wrong exception, and actually the traceback seems not full and we can’t see the real exception causing the problem.
Now I understand what is happening. When rendering the template and you have something like
{{ var.attr }}
, django actually is trying first to getattr
as key from dictionary instead of attribute of an object. When this fails withTypeError
because the object is not subscriptable (it’s not dictionary like) then it tries to get it as attribute of that object. And now because this attribute (probablyurl
orwith
/height
) is a property and not simple value then some logic is executed which raised the error. We care about the second error.