Viewing Product in the admin leads to SuspiciousOperation

Issue #1495 resolved
caleb smith created an issue

When trying to view a Product in the admin, if it has an image attached, the thumbnail widget raises a SuspiciousOperation because the MEDIA_ROOT before the image is removed and Django can't get to the path provided.

The following is a traceback that occurs when attempting to view a Product with an image

Environment:

Request Method: GET Request URL: http://localhost:8000/admin/product/product/89/

Django Version: 1.5.5 Python Version: 2.7.3 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'django.contrib.sitemaps', 'django.contrib.sites', 'sorl.thumbnail', 'haystack', 'satchmo_store.shop', 'keyedcache', 'livesettings', 'l10n', 'satchmo_utils.thumbnail', 'satchmo_store.contact', 'tax', 'tax.modules.no', 'tax.modules.area', 'tax.modules.percent', 'shipping', 'shipping.modules.no', 'product', 'product.modules.configurable', 'product.modules.custom', 'product.modules.subscription', 'product.modules.downloadable', 'payment', 'payment.modules.authorizenet', 'satchmo_ext.satchmo_toolbar', 'satchmo_ext.tieredpricing', 'satchmo_utils', 'app_plugins', 'south', 'cms', 'mptt', 'menus', 'sekizai', 'filer', 'cms.plugins.text', 'cms.plugins.link', 'cms.plugins.snippet', 'cmsplugin_filer_file', 'cmsplugin_filer_folder', 'cmsplugin_filer_image', 'cmsplugin_filer_teaser', 'cmsplugin_filer_video', 'easy_thumbnails', 'reversion', 'smart_load_tag', 'django_forms_bootstrap', 'apps.sf_avatar', 'avatar', 'tagging', 'selectable', 'tinymce', 'pagination', 'projectname.plugins.home_page_section', 'projectname.plugins.members', 'projectname.plugins.navigation', 'projectname.plugins.collapsible_panel', 'nasft_membership', 'multi_image_uploader', 'apps.sf_registration', 'apps.util', 'apps.show_data', 'apps.organization', 'apps.articles', 'apps.tw_init', 'django.contrib.admin') Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'pagination.middleware.PaginationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware')

Template error: In template /home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19 Attempted access to '/images/productimage-picture-nasftsg4_ne-68.png' denied. 9 : {% for field in line %}

10 : <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}"{% endif %}>

11 : {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}

12 : {% if field.is_checkbox %}

13 : {{ field.field }}{{ field.label_tag }}

14 : {% else %}

15 : {{ field.label_tag }}

16 : {% if field.is_readonly %}

17 : <p>{{ field.contents|linebreaksbr }}</p>

18 : {% else %}

19 : {{ field.field }}

20 : {% endif %}

21 : {% endif %}

22 : {% if field.field.help_text %}

23 : <p class="help">{{ field.field.help_text|safe }}</p>

24 : {% endif %}

25 : </div>

26 : {% endfor %}

27 : </div>

28 : {% endfor %}

29 : </fieldset>

Traceback: File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 140. response = response.render() File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/response.py" in render 105. self.content = self.rendered_content File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content 82. content = template.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 140. return self.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 124. return compiled_parent._render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 124. return compiled_parent._render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 124. return compiled_parent._render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 63. result = block.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 63. result = block.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 189. nodelist.append(node.render(context)) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 167. return self.render_template(template, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render_template 138. output = template.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 140. return self._render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 189. nodelist.append(node.render(context)) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 189. nodelist.append(node.render(context)) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render 156. return self.render_template(self.template, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render_template 138. output = template.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 140. return self._render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 189. nodelist.append(node.render(context)) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 189. nodelist.append(node.render(context)) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 285. return nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render 285. return nodelist.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/base.py" in render 830. bit = self.render_node(node, context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render_node 74. return node.render(context) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/template/debug.py" in render 87. output = force_text(output) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/utils/encoding.py" in force_text 99. s = s.unicode() File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/forms/forms.py" in str 411. return self.as_widget() File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/forms/forms.py" in as_widget 458. return widget.render(name, self.value(), attrs=attrs) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/satchmo_utils/thumbnail/widgets.py" in render 26. quality=config_value('THUMBNAIL', 'IMAGE_QUALITY')) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/sorl/thumbnail/shortcuts.py" in get_thumbnail 8. return default.backend.get_thumbnail(file, geometry_string, **options) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/sorl/thumbnail/base.py" in get_thumbnail 56. source_image = default.engine.get_image(source) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/sorl/thumbnail/engines/pil_engine.py" in get_image 12. buf = StringIO(source.read()) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/sorl/thumbnail/images.py" in read 121. return self.storage.open(self.name).read() File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/core/files/storage.py" in open 36. return self._open(name, mode) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/core/files/storage.py" in _open 159. return File(open(self.path(name), mode)) File "/home/csmith/Envs/projectname/local/lib/python2.7/site-packages/django/core/files/storage.py" in path 259. raise SuspiciousOperation("Attempted access to '%s' denied." % name)

Exception Type: SuspiciousOperation at /admin/product/product/89/ Exception Value: Attempted access to '/images/productimage-picture-nasftsg4_ne-68.png' denied.

The fix I expect to work is to pass the image's path directly to the get_thumbnail() function in thumbnails/widget.py

Comments (2)

  1. Log in to comment