Aquisition, __iter__ and __getitem__ in Zope 2.12.0a1

Reported by ChrisW on 2009-04-13
8
Affects Status Importance Assigned to Milestone
Zope 2
Medium
Andi Zeidler

Bug Description

This shouldn't happen:

 >>> class C(Implicit):
... l=[1,2,3]
... def __getitem__(self, i):
... return self.l[i]
...
 >>> c=C()
 >>> iter(c)
<iterator object at 0xb7dbb38c>
 >>> list(_)
[1, 2, 3]
 >>> c2=C().__of__(c)
 >>> iter(c2)
Traceback (most recent call last):
   File "<console>", line 1, in <module>
AttributeError: __iter__

See this post:

http://mail.zope.org/pipermail/zope-dev/2009-April/036020.html

...for the change that causes the bug.

Changed in zope2:
status: New → Confirmed
Andi Zeidler (witsch) wrote :

this has been fixed in http://svn.zope.org/?view=rev&rev=99191

chris, could you please verify (and hopefully also close)?

Andi Zeidler (witsch) wrote :

i'm setting this to "fixed" pro-actively, please re-open if you find more issues...

Changed in zope2:
assignee: nobody → az-zitc
status: Confirmed → Fix Committed
ChrisW (chris-simplistix) wrote :

Just to confirm that this works for me, and is in Zope 2.12.0a3

Changed in zope2:
status: Fix Committed → Fix Released
Martijn Faassen (faassen) wrote :

The iterator support leads to problems for us - acquisition wrappers are lost during iteration. Here is an example that uses __iter__:

from Acquisition import Implicit

class B(Implicit):
    def __iter__(self):
        for i in range(5):
            yield i, self.aq_parent

class A(Implicit):
    pass

a = A()
a.b = B()

for (i, parent) in a.b:
    print i, parent

'self.aq_parent' fails here, as 'self' inside __iter__ isn't acquisition wrapped.

Worse is that *existing* code that has worked for years (namely ParsedXML) suddenly breaks, as it uses __getitem__ based iteration. The problem now is that this *always* uses iterators now, instead of using the old fallback. This means acquisition wrappers are lost within __getitem__ too now:

from Acquisition import Implicit

class B(Implicit):
    def __getitem__(self, i):
        if i == 5:
            raise IndexError()
        return i, self.aq_parent

class A(Implicit):
    pass

a = A()
a.b = B()

for (i, parent) in a.b:
    print i, parent

We do not know whether the implementation before this bugfix worked better with __iter__ but in any case we'd then again have the original reported issue that __getitem__ breaks.

We are seeing this issue appear in Zope 2.11.3, to which we're trying to port Silva, which relies on ParsedXML.

Changed in zope2:
status: Fix Released → Incomplete
status: Incomplete → New

On Sep 25, 2009, at 5:23 PM, Martijn Faassen wrote:
> The iterator support leads to problems for us - acquisition wrappers
> are
> lost during iteration. Here is an example that uses __iter__:

hi martijn,

i'll have a look, but need to wrap up my plone4 plips first. iow,
it'll be a few more days...

cheers,

andi

--
zeidler it consulting - http://zitc.de/ - <email address hidden>
friedelstraße 31 - 12047 berlin - telefon +49 30 25563779
pgp key at http://zitc.de/pgp - http://wwwkeys.de.pgp.net/
plone 3.3.1 released! -- http://plone.org/products/plone/

Andreas Jung (ajung) on 2009-09-30
Changed in zope2:
importance: Undecided → Medium
Andreas Jung (ajung) wrote :

This must be fixed for 2.12.1
(not a blocker for 2.12.0)

Tres Seaver (tseaver) wrote :

I'm attaching a patch which adds (breaking) tests for both the case
that the wrapped object has an __iter__ and the case where the wrapper
proxy falls back to __getitem__. The new tests assert that __iter__ and
__getitem__ get passed a wrapped self.

Andreas Jung (ajung) on 2009-10-26
Changed in zope2:
status: New → Confirmed
Andi Zeidler (witsch) wrote :

the problem should have been fixed in r105350:

  http://svn.zope.org/?rev=105350&view=rev

and backported to 2.10 and 2.11 in:

  http://svn.zope.org/?rev=105352&view=rev

  http://svn.zope.org/?rev=105353&view=rev

Martijn, could you please verify if the fix works for you before Andreas makes the next release?

Changed in zope2:
status: Confirmed → Fix Committed
Tres Seaver (tseaver) wrote :

The Acquisition 2.12.4 egg is released.

Changed in zope2:
status: Fix Committed → Fix Released

Seems to work indeed, the problem we had which was caused by this issue (ParsedXML not working in certain circumstances) seems to have vanished. Thanks!

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers