Opened 4 weeks ago

Last modified 2 weeks ago

#36998 assigned Bug

firstof tag doesn't require an argument when used with as var

Reported by: Lily Owned by: Shubh Rai
Component: Template system Version: 6.0
Severity: Normal Keywords:
Cc: Pravin, Shubh Rai Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

The {% firstof %} template tag raises a TemplateSyntaxError("'firstof' statement requires at least one argument") when called with no arguments.

However, when called with exactly two arguments that match the variable capturing syntax (e.g. {% firstof as foo %}) no error is raised and the FirstOfNode is returned with an empty vars list (and an asvar of e.g. foo). It would be consistent to raise a TemplateSyntaxError("'firstof' statement requires at least one argument before 'as'") here.

This was discovered when re-implementing `firstof` in django-rusty-templates.

Change History (8)

comment:1 by Pravin, 4 weeks ago

Cc: Pravin added

comment:2 by Shubh Rai, 4 weeks ago

Cc: Shubh Rai added
Has patch: set
Owner: set to Shubh Rai
Status: newassigned

comment:3 by Aniket Gupta, 4 weeks ago

Triage Stage: UnreviewedAccepted

Hi Lily, thanks for catching and reporting this!

I can confirm this bug is still present on the main branch. I was able to isolate and reproduce the silent failure using a minimal, standalone Django script, confirming that this is a core parser issue and independent of django-rusty-templates. As reported, evaluating Template('{% firstof as foo %}') returns an empty node instead of raising the expected TemplateSyntaxError.

I am upgrading the Triage Stage to 'Accepted' and I would be very happy to write the patch and submit a PR for the fix!

Last edited 4 weeks ago by Aniket Gupta (previous) (diff)

comment:4 by Shubh Rai, 4 weeks ago

I have opened a pr:https://github.com/django/django/pull/20978, Please let me know if any changes are required.

comment:5 by Tim McCurrach, 2 weeks ago

Patch needs improvement: set

I'd probably also close the existing PR - on the basis that it was done by AI as part of a massive batch of PRs and so doesn't meet our contributing guidelines, and is unlikely to be revisited by the author.

in reply to:  5 ; comment:6 by Shubh Rai, 2 weeks ago

my earlier pr was closed since another contributor was already working on this issue.Given the recent discussion about the existing PR would it be okay for me to reopen or submit an updated PR?

in reply to:  6 comment:7 by Tim McCurrach, 2 weeks ago

Replying to Shubh Rai:

my earlier pr was closed since another contributor was already working on this issue.Given the recent discussion about the existing PR would it be okay for me to reopen or submit an updated PR?

I'm sure this will be fine - but it's a good idea to wait until either the previous PR has been closed, or a long enough time has passed with no activity (think at least a month or two).

comment:8 by Shubh Rai, 2 weeks ago

okay I will wait till then.

Note: See TracTickets for help on using tickets.
Back to Top