Opened 8 years ago

Closed 8 years ago

Last modified 8 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 by Simon Charette, 8 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In b412681:

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

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 04780e8a:

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

Backport of b41268135995cef46d40e550f9301fab20cf330d from master

comment:7 by Tim Graham <timograham@…>, 8 years ago

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