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 , 4 weeks ago
| Cc: | added |
|---|
comment:2 by , 4 weeks ago
| Cc: | added |
|---|---|
| Has patch: | set |
| Owner: | set to |
| Status: | new → assigned |
comment:3 by , 4 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:4 by , 4 weeks ago
I have opened a pr:https://github.com/django/django/pull/20978, Please let me know if any changes are required.
follow-up: 6 comment:5 by , 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.
follow-up: 7 comment:6 by , 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?
comment:7 by , 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).
Hi Lily, thanks for catching and reporting this!
I can confirm this bug is still present on the
mainbranch. 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 ofdjango-rusty-templates. As reported, evaluatingTemplate('{% firstof as foo %}')returns an empty node instead of raising the expectedTemplateSyntaxError.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!