[Zodb-checkins] CVS: Zope3/src/zodb/tests - test_connection.py:1.9

Steve Alexander steve at z3u.com
Wed Oct 15 10:26:22 EDT 2003


Jeremy Hylton wrote:
> On Wed, 2003-10-15 at 08:00, Marius Gedminas wrote:
> 
>>Update of /cvs-repository/Zope3/src/zodb/tests
>>In directory cvs.zope.org:/tmp/cvs-serv27246/tests
>>
>>Modified Files:
>>	test_connection.py 
>>Log Message:
>>There was a problem with modifying a persistent object during its
>>__getstate__ method, during a transaction savepoint or commit.
>>There was also a similar problem when calling connection.add() during
>>the time a connection is preparing to commit.
>>These are all different manifestations of the same problem: the registered
>>objects mapping in a connection cannot be modified during an iteration over
>>its keys or values or items.
> 
> 
> I actually intended that it not be possible to modify objects or add
> objects to a connection after the transaction commit has begun.  Can you
> provide a rationale for adding this feature?

We have a collection object that uses persistent objects as its keys.

We do not want to make all persistent objects that can be used with this 
container derive from a particular class.

The collection object works by using a persistent object's _p_oid as a key.

The collection object is itself a persistent object. If a persistent 
object is added to the collection, if the collection has a _p_jar and 
the persistent object also has a _p_jar and _p_oid, the persistent 
object is added to the collection keyed on its _p_oid. Otherwise, the 
persistent object is stored in a temporary mapping, keyed by 
id(persistent_object). When __getstate__ is called on the collection, 
before returning its state the collection calls self._p_jar.add(obj) on 
each object in the temporary mapping, and then adds that object to the 
collection proper, keyed on its _p_oid.

See class PersistentKeysDict in this module:

http://source.schooltool.org/svn/trunk/schooltool/src/schooltool/db.py

--
Steve Alexander




More information about the Zodb-checkins mailing list