2010/1/6 Martin Aspeli <optilude+li...@gmail.com>: > Hi, > > This one is pretty high no the list of weirdest things to have happened > to me in a while. Basically, I have a persistent object that has an > empty __dict__() on the first request, until it suddenly decides to have > data again. > > I'm on ZODB 3.9.3, using Zope 2.12 and Plone 4. I have a persistent > object, /plone/portal_registry: > > class Registry(registry.Registry, SimpleItem): > pass > > The base class is: > > class Registry(Persistent): > def __init__(self): > self._records = Records(self) > > Records is: > > class Records(Persistent): > > __parent__ = None > > def __init__(self, parent): > self.__parent__ = parent > self.data = OOBTree() > > def __getitem__(self, name): > return self.data.__getitem__(name) > > The BTree contains string keys and Record objects as values. Record is: > > class Record(Persistent): > __name__ = u"" > __parent__ = None > > field = None > > __parent__ is set to records.__parent__, which is going to be the > Registry object. > > field is set to a special persistent field class inheriting from > zope.schema's fields, but mixing in persistence. In this case, I have a > list field: > > class PersistentField(persistent.Persistent): > """Base class for persistent field definitions. > """ > > class PersistentCollectionField(PersistentField, > zope.schema._field.AbstractCollection): > > class List(PersistentCollectionField, zope.schema.List): > pass > > I then have some code like this: > > def cloneField(self, field): > clone = field.__class__.__new__(field.__class__) > clone.__dict__.update(field.__dict__) > for name, attr in field.__dict__.items(): > if IField.providedBy(attr): > clone.__dict__[name] = self.cloneField(attr) > return clone > > This is used like so: > > registry = getUtility(IRegistry) # persistent/local > clone = self.cloneField(registry.records[recordName].field) > > This seems to work always *except* on the first request immediately > after starting up Zope. In this case, field.__dict__ is {}. If I poke at > it long enough in pdb, it suddenly springs into life and contains values > again. > > Can anyone enlighten me as to: > > - why this may happen > - how I can ensure it stops happening :-)
I don't know if this should ever happen when you access persistentobj.__dict__, but it sounds as if it is in the ghost state. What is clone._p_state at this point (-1 would be a ghost object, 0 = normal object, 1 = modified object). You could do clone._p_activate() first. Laurence _______________________________________________ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev