Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#26267 closed Bug (fixed)

Template filter "slice" raises TypeError on bound RadioSelect

Reported by: Jon Dufresne Owned by: nobody
Component: Template system Version: 1.8
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a template with the following snippet:

{% for choice in form.choices|slice:'1:' %}
    <li>{{ choice }}</li>
{% endfor %}

Where choices is a ChoiceField with a RadioSelect widget. This stopped working in 1.8.

Looking through the code history, this looks like it was introduce in commit 5e06fa14 during work on ticket #22745.

The change to BoundField.__getitem__():

      def __getitem__(self, idx):
+        # Prevent unnecessary reevaluation when accessing BoundField's attrs
+        # from templates.
+        if not isinstance(idx, six.integer_types):
+            raise TypeError
         return list(self.__iter__())[idx]

It no longer accepts a slice and will instead raise a TypeError.

Change History (7)

comment:1 Changed 4 years ago by Simon Charette

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:4 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In b412681:

Fixed #26267 -- Fixed BoundField to reallow slices of subwidgets.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In 04780e8a:

[1.9.x] Fixed #26267 -- Fixed BoundField to reallow slices of subwidgets.

Backport of b41268135995cef46d40e550f9301fab20cf330d from master

comment:7 Changed 4 years ago by Tim Graham <timograham@…>

In 6c48eda:

[1.8.x] Fixed #26267 -- Fixed BoundField to reallow slices of subwidgets.

Backport of b41268135995cef46d40e550f9301fab20cf330d from master

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