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

Jürgen Kartnaller juergen at kartnaller.at
Sun Feb 25 11:40:26 EST 2007



Christophe Combelles wrote:
> Hello,
> 
> I've been spending several hours on a problem which is probably trivial 
> for advanced zope3ers, but it was not for me, so I'm posting the 
> solution in case it's useful for someone (I've not found anything on it).
> 

http://mail.zope.org/pipermail/zope3-users/2005-November/001494.html

> 
> The problem:
> I want to create a folder, and when this folder is created, several 
> subfolders should be automatically created.  And I have a IntId utility. 
> (this is part of the problem).
> 
> First, I've tried to create the subfolders in the __init__ method of the 
> folder being created. It does not work and fails with a NotYet error.
> 
> Then, I've tried to create the subfolders in the create method of the 
> AddForm, after the folder has been eventually created. Still too early: 
> NotYet error.
> 
> 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.

> 
> 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.

Jürgen



More information about the Zope3-users mailing list