Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
khink opened this issue Jan 25, 2023 · 0 comments
Open

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

khink opened this issue Jan 25, 2023 · 0 comments

Comments

@khink
Copy link

khink commented Jan 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant