Opened 21 months ago
Closed 21 months ago
#34335 closed Bug (wontfix)
Spurious error when using label_tag of CheckboxSelectMultiple widget
Reported by: | Mark Theng | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the label_tag
method of BoundField, if attrs == None
and id_for_label == ""
(as is possible with CheckboxSelectMultiple/RadioSelect), it is possible for the attrs passed into the context to be None. attrs.items
is used directly in the attrs.html
template without checking if attrs
exists, resulting in the error django.template.base.VariableDoesNotExist: Failed lookup for key [items] in None
.
This would be easily fixed by either passing attrs or {}
into the context in the label_tag
method, or adding an if attrs
guard in attrs.html
.
I have checked that this issue still exists on the main branch.
Thanks for this report, however many templates, including some of the Django's templates, rely upon the silence of the template system when a nonexistent variable is encountered. I don't think it's worth tracking and changing them (see also #28526).