zope calls list(iterable) whenever we use tal:repeat="item iterable"

Bug #4819 reported by Guilherme Salgado
2
Affects Status Importance Assigned to Milestone
BlueBream
New
Undecided
Unassigned
Launchpad itself
Fix Released
Medium
Unassigned
Zope 3
Won't Fix
Undecided
Unassigned
zope.tal
Invalid
Undecided
Unassigned

Bug Description

I don't see any reason why this needs to be done, and it can be a problem because is some cases the result can be something you don't expect. For instance, with sqlobject, if you do a list(SelectResults), it'll issue a COUNT(*) query with that SelectResult's WHERE clause, which is not issued if you iterate over SelectResults. One can argue this is a bug in sqlobject (and I do agree), but I still think this has to be fixed in zope too.

Revision history for this message
Guilherme Salgado (salgado) wrote : Patch to print the issued queries on stdout

Apply this patch and go to http://localhost:8086/+portlet-foaf to see the extra COUNT(*) query.

Changed in launchpad:
assignee: nobody → stevea
Revision history for this message
James Henstridge (jamesh) wrote :

The extra COUNT(*) is because of an allocation optimisation when converting an iterable to a list: if the iterable provides a __len__() method, it is called first. That many items are allocated in the new list and then filled by iterating over the list.

For SQLObject, this optimisation hurts performance overall. The additional query could be avoided if SelectResults.__len__() was removed (but that might cause other problems).

Dafydd Harries (daf)
Changed in launchpad:
status: New → Accepted
Changed in launchpad:
assignee: stevea → nobody
Revision history for this message
David Allouche (ddaa) wrote :

The sqlobject currently used by Launchpad does not provide SelectResults.__len__().

Tres Seaver (tseaver)
Changed in zope3:
status: New → Won't Fix
Fred Drake (fdrake)
Changed in zope.tal:
status: New → Confirmed
Tres Seaver (tseaver)
tags: added: bugday20100424
Revision history for this message
Robert Collins (lifeless) wrote :

So the issue here for LP is reasonably paraphrased as 'our ORM result sets had a __len__ method'. We probably want to ensure they don't and add a test for that to prevent regressions. That said, we already havge ditched __len__, so I'm going to close this as fixreleased for LP.

Changed in launchpad:
status: Triaged → Fix Released
Revision history for this message
Colin Watson (cjwatson) wrote :

The zope.tal project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope.tal.

Changed in zope.tal:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.