[Zope-dev] ZPatterns AttributeProvider question

Steve Alexander steve@cat-box.net
Sun, 22 Apr 2001 15:07:52 +0100


Christian Scholz wrote:

>
> So what I do now as workaround is 
> 
> dtml method 1:
> 
> - creates new object via newItem()
> - redirects to dtml method 2
> 
> dtml method 2:
> - retrieves the newly created object with getItem()
> - calls manage_changeProperties on that object
> 
> This is working. Putting the manage_changeProperties directly after the
> newItem() is not working. I've also tried retrieving the new object
> directly after newItem() and calling manage_changeProperties on that
> but this also did not work.
> (so it is named correctly as otherwise it wouldn't be called either in dtml method 2).
> 
> So the main problem is: SetAttributeFor() is not called (and also _objectChanging()
> is not called) in the same request cycle after creating a new object.
> They're called however in the "next" request after retrieving it with getItem().


   As a simpler workaround, you can use 
your_object.commitSubtransaction() instead of redirecting to a new page. 
A few Zope versions ago, that could conceivably cause problems with 
certain database adapters. With some of the recent fixes to Zope, you 
should be ok using subtransactions even with DAs that don't support 
them. Check this out before you use it for important stuff though :-)

   You really should be able to create a new object and set its 
attributes in the same transaction. The status of the object (_v_status 
in DataSkin.py) will be ChangedStatus, if you're adding and changing in 
the same transaction. That's a good place to look for where the problem is.

--
Steve Alexander
Software Engineer
Cat-Box limited