[Django] #36998: firstof tag doesn't require an argument when used with as var

32 views
Skip to first unread message

Django

unread,
Mar 22, 2026, 6:10:20 AMMar 22
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
----------------------+-------------------------------------------
Reporter: Lily | Type: Bug
Status: new | Component: Template system
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------+-------------------------------------------
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 [https://github.com/LilyFirefly/django-rusty-
templates/pull/366/changes#r2971319569 re-implementing `firstof` in
django-rusty-templates].
--
Ticket URL: <https://code.djangoproject.com/ticket/36998>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 22, 2026, 6:22:19 AMMar 22
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+--------------------------------------
Reporter: Lily | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Pravin):

* cc: Pravin (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:1>

Django

unread,
Mar 23, 2026, 12:47:44 PMMar 23
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+--------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Shubh Rai):

* cc: Shubh Rai (added)
* has_patch: 0 => 1
* owner: (none) => Shubh Rai
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:2>

Django

unread,
Mar 23, 2026, 2:25:30 PMMar 23
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by Aniket Gupta):

* stage: Unreviewed => Accepted

Comment:

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!
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:3>

Django

unread,
Mar 24, 2026, 3:01:31 AMMar 24
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by Shubh Rai):

I have opened a pr:[https://github.com/django/django/pull/20978], Please
let me know if any changes are required.
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:4>

Django

unread,
Apr 2, 2026, 5:16:55 AMApr 2
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by Tim McCurrach):

* needs_better_patch: 0 => 1

Comment:

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:5>

Django

unread,
Apr 2, 2026, 11:35:43 AMApr 2
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by 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?
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:6>

Django

unread,
Apr 2, 2026, 11:52:04 AMApr 2
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by Tim McCurrach):

Replying to [comment:6 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).
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:7>

Django

unread,
Apr 2, 2026, 12:06:56 PMApr 2
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by Shubh Rai):

okay I will wait till then.
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:8>

Django

unread,
Apr 27, 2026, 4:47:13 AMApr 27
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by Shubh Rai):

Its been almost a month without the activity of the previous contributor ,
can I work on it and open a pr?
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:9>

Django

unread,
May 11, 2026, 11:37:37 PMMay 11
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+-------------------------------------
Reporter: Lily | Owner: Shubh Rai
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
---------------------------------+-------------------------------------
Comment (by Vaibhav Pant):

Hey , I'm a beginner open source contributor and I've been looking into
this ticket. I went through the previous PRs and the review comments to
understand what went wrong earlier.

I've implemented the fix — adding a check inside the `as` parsing block
that raises a `TemplateSyntaxError` with the message `"'firstof' statement
requires at least one argument before 'as'"` when no variables are
provided before `as`.

I also added a regression test following the same `@setup` pattern used in
the existing test file, taking reference from how the earlier patch
approached testing. All 17 tests are passing locally.

I would love to open a PR for this if it's okay. Please let me know if
there's anything I should fix or change before I do!
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:10>

Django

unread,
Jun 23, 2026, 3:15:54 PM (21 hours ago) Jun 23
to django-...@googlegroups.com
#36998: firstof tag doesn't require an argument when used with as var
---------------------------------+------------------------------------
Reporter: Lily | Owner: awath
Type: Bug | Status: assigned
Component: Template system | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by awath):

* needs_better_patch: 1 => 0
* owner: Shubh Rai => awath

Comment:

I created a new PR for this issue at
[https://github.com/django/django/pull/21534 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/36998#comment:11>
Reply all
Reply to author
Forward
0 new messages