Skip to content

Should an empty thumbnail template tag raise an exception? #720

@khink

Description

@khink

According to https://sorl-thumbnail.readthedocs.io/en/latest/examples.html#template-examples, a thumbnail template tag requires at least an image argument and a geometry string: {% thumbnail item.image "100x100" %}

However, an empty tag {% thumbnail %} does not give an error (as omitting the geometry string does). I checked this with THUMBNAIL_DEBUG = True.

One time when the error surfaces is when running django-compressor's ./manage.py compress. This results in an IndexError list index out of range from sorl/thumbnail/templatetags/thumbnail.py in __init__ at line 96:

    def __init__(self, parser, token):
        bits = token.split_contents()
        self.file_ = parser.compile_filter(bits[1])

Turns out that i hadn't been paying attention while copy/pasting a lot of thumbnail tags, and instead of {% endthumbnail %} i'd put {% thumbnail %}.

I think it would be better if sorl.thumbnail raises an exception on empty template thumbnail tags, especially if THUMBNAIL_DEBUG = True, because empty tags do nothing and can only be an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions