[Zope3-Users] Re: NotYet error when creating content during container creation

Philipp von Weitershausen philipp at weitershausen.de
Sun Feb 25 12:23:54 EST 2007


Jürgen Kartnaller wrote:
>> I've also tried to create the subfolders in a subscriber on 
>> IObjectCreatedEvent, but this is equivalent to the previous attempt : 
>> NotYet error.
>>
>> What I've understood is that the transaction that manages the folder 
>> is not finished, and the IntId utility is not yet able to get a 
>> connection on the ZODB. So I've tried to create an adapter to 
>> IConnection for my subfolder, so that it can use the same connection 
>> as the folder. But I couldn't. (however it might be possible?).
> 
> 'NotYet' happens if the object in not connected to a database. The 
> connection to the database exists as soon as your object is added to the 
> object tree in zope. It is not related to a finished transaction.

That's not entirely true. The problem's origin is in 
zope.app.keyreference. In order to give newly created objects an integer 
id, the objects need to be adaptable to IKeyReference. The IKeyReference 
adapter for persistnet objects wants access to the object's database 
("pickle jar").

Now, if the object has already been persisted before in an *already 
committed transaction*, it will have a _p_jar attribute. So, if the 
transaction were in fact finished, the IKeyReference adapter could take 
the object's _p_jar attribute right away.

But since the transaction isn't over yet and the object was just 
created, it has no _p_jar attribute, so the IKeyReference adapter does a 
bit of guessing. It walks up the __parent__ hierarchy and figures that 
if the newly created object is part of a container somewhere, it will be 
persisted in the same database. So it takes the container's _p_jar. This 
is the reason why IKeyReference wants an intact __parent__ hierarchy for 
newly created objects.

>> The simple solution is to create the subfolders AFTER the folder has 
>> been eventually ADDED with the add method. So in the AddForm, I've 
>> replaced the create() method with a createAndAdd method. In this 
>> method, I've just created my folder, called add to add it, then only I 
>> could create the subfolders and add them to the folder.
> 
> You can also do this using an event handler for ObjectAddedEvent on your 
> Folder. In this case you do not need to touch any code in your form.

Yes, this is what I'd recommend. A handler for an ObjectAddedEvent will 
always see the object already as part of the object hierarchy (which is, 
after all, what ObjectAddedEvent is about).

-- 
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5



More information about the Zope3-users mailing list