copy corrupts BTrees.Length.Length instances

Bug #516653 reported by Albertas Agejevas
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released

Bug Description

Copying BTrees.Length.Length fails when the stored length value is 0:

>>> from BTrees.Length import Length
>>> import copy
>>> l = Length()
>>> print l()
>>> c = copy.deepcopy(l)
>>> print c()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/alga/src/eggs/ZODB3-3.9.4-py2.5-linux-i686.egg/BTrees/", line 58, in __call__
    return self.value
AttributeError: 'Length' object has no attribute 'value'

This failure occurs because Length returns its stored value as the result of __getstate__, and the copy module's _reconstruct function uses the state value as a condition. It is a bug in copy (pickling/unpickling works fine), but it makes sense to add a class attribute value = 0 as a workaround until the proper fix is propagated in Python.

Revision history for this message
Albertas Agejevas (alga) wrote :

This bug is reported on the Python bugtracker as .

Revision history for this message
Marius Gedminas (mgedmin) wrote :

The Official Python Documentation states

   Note: For new-style classes, if __getstate__() returns a false value, the __setstate__() method will not be called.


It would appear that copy.deepcopy() is working as per spec, and it's just a happy accident that pickling BTrees.Length.Length() instances with the value of 0 works.

The fix should be trivial: add a class attribute 'value = 0' to BTrees.Length.Length.

Revision history for this message
Albertas Agejevas (alga) wrote :

Fix committed in trunk rev 108750.

Changed in zodb:
status: New → Fix Committed
Revision history for this message
Tres Seaver (tseaver) wrote :

Fix released in ZODB 3.10.0a2 (not noted in changelog at time of release).

Changed in zodb:
status: Fix Committed → Fix Released
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.