[Z3-sqlos] Re: [z3] sqlos: add view for SQLOS objects

Christian Lück christian.lueck at ruhr-uni-bochum.de
Sat Jan 21 21:12:07 CET 2006


Brian Sutherland wrote:
> On Sat, Jan 21, 2006 at 12:44:55AM +0000, Christian Lück wrote:
>> Brian Sutherland wrote:
>> > On Sat, Jan 07, 2006 at 06:20:42PM +0000, Christian L�ck wrote:
>> Whenever I try to add an item with a <browser:addForm> view, I get the
>> follwing exception:
>> 
>> 2006-01-20T22:20:21 ERROR txn.-1236755536 Failed to abort resource
>> manager: <transaction._transaction.DataManagerAdapter object at 0xb52ae6cc>
>> Traceback (most recent call last):
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/transaction/_transaction.py",
>> line 507, in abort
>>     rm.abort(self)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/transaction/_transaction.py",
>> line 634, in abort
>>     self._datamanager.abort(transaction)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/app/rdb/__init__.py",
>> line 445, in abort
>>     self._dbconn.rollback()
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/app/rdb/__init__.py",
>> line 391, in rollback
>>     self.conn.rollback()
>> NotSupportedError: (1196, "Warning:  Some non-transactionalchanged
>> tables couldn't be rolled back")
>> Traceback (most recent call last):
>>   File "/usr/local/lib/python2.4/threading.py", line 422, in run
>>     self.__target(*self.__args, **self.__kwargs)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/twisted/python/threadpool.py",
>> line 149, in _worker
>>     context.call(ctx, function, *args, **kwargs)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/twisted/python/context.py",
>> line 59, in callWithContext
>>     return self.currentContext().callWithContext(ctx, func,*args, **kw)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/twisted/python/context.py",
>> line 37, in callWithContext
>>     return func(*args,**kw)
>> --- <exception caught here> ---
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/twisted/web2/wsgi.py",
>> line 139, in run
>>     result = self.application(self.environment, self.startWSGIResponse)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/app/wsgi/__init__.py",
>> line 54, in __call__
>>     request = publish(request, handle_errors=handle_errors)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/publisher/publish.py",
>> line 146, in publish
>>     publication.handleException(
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/app/publication/zopepublication.py",
>> line 243, in handleException
>>     transaction.abort()
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/transaction/_manager.py",
>> line 107, in abort
>>     return self.get().abort(sub, deprecation_wng=False)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/transaction/_transaction.py",
>> line 507, in abort
>>     rm.abort(self)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/transaction/_transaction.py",
>> line 634, in abort
>>     self._datamanager.abort(transaction)
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/app/rdb/__init__.py",
>> line 445, in abort
>>     self._dbconn.rollback()
>>   File
>> "/usr/local/src/Zope-3.2.0b2/build/lib.linux-i686-2.4/zope/app/rdb/__init__.py",
>> line 391, in rollback
>>     self.conn.rollback()
>> _mysql_exceptions.NotSupportedError: (1196, "Warning:
>> Somenon-transactional changed tables couldn't be rolled back")
> 
> I have seen this before and wondered if there should be a bare try:
> except: clause around the rollback in zope.app.rdb.
> 
> If you can't rollback, you are lost anyway, no point in bringing the
> whole transaction machinery down with you.
> 
>> 127.0.0.1 - - [20/Jan/2006:22:20:21 +0100] "POST
>> /persons/+/AddPerson.html%3D HTTP/1.1" 500 201
>> "http://localhost:8080/persons/+/AddPerson.html=" "Mozilla/5.0 (X11; U;
>> Linux i686;de-DE; rv:1.7.10) Gecko/20050925 Firefox/1.0.4 (Debian
>> package 1.0.4-2sarge5)"
>> 127.0.0.1 - - [20/Jan/2006:22:20:21 +0100] "GET /favicon.ico HTTP/1.1"
>> 404 4133 "-" "Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.7.10)
>> Gecko/20050925 Firefox/1.0.4 (Debian package 1.0.4-2sarge5)"
>> 
>> 
>> To avoid this, I wrote a view class for my add-view. There I override
>> the add() method which is inherited from
>> zope.app.form.browser.add.AddView. It calls the add() method of
>> the context, which - if I'm not totally wrong - should implemet IAdding.
> 
> Yes, indeed it should implement IAdding, and you can adapt your
> SQLObjectContainer to that interface with this directive:
> 
>   <browser:view
>       name="+"
>       menu="zmi_actions" title="Add SQLObjects"
>       for="sqlos.testing.sampleperson.IMultiContainer"
>       permission="zope.ManageContent"
>       class="zope.app.container.browser.adding.Adding"
>       >
>     <browser:page name="index.html" attribute="index"/>
>     <browser:page name="action.html" attribute="action"/>
>   </browser:view>
> 
>> from zope.app.form.browser.add import AddView
>> 
>> class PersonAddView(AddView):
>> 
>>     __used_for__ = IPerson
>> 
>>     def add(self, content):
>>         """In sqlos we yust intantiate an object and then it appears
>>         in the container, but we don't really add an object to a container.
>>         So we override this method here."""
>>         return content
> 
> This type of thing really shouldn't be necessary as adding objects to a
> sqlos container should really be a no-op.

Yes, I have seen the code in container.py:

    def __setitem__(self, name, content):
        return name

> 
> However I have a funny feeling that the interface declarations in SQLOS
> need some tweaking. For instance it appears possible in the zmi to add
> SQLOS objects even to normal Zope3 Folders. That is bound to fail unless
> you use an AddView like the one above.
> 
> I'm sure a read about how to do this in Stephan Richter's book
> somewhere...
> 
>> Its Registration:
>> 
>>   <addform
>>       schema="sqlosperson.interfaces.IPerson"
>>       content_factory="sqlosperson.person.Person"
>>       class=".person.PersonAddView"
>>       name="AddPerson.html"
>>       label="Add Person"
>>       permission="zope.ManageContent"
>>       />
>> 
>> But if sqlos wants to make it easy to plug a rdb instead of ZODB, then
>> having to change all your add views is not acceptable..
>> I thought about rewriting __setitem()__ and __getitem()__
>> for the container class - but as far as I see, it's yust coded the way I
>> was thinking of. Well I really don't have an idea..
> 
> I think the problem here is that you are trying to add sqlos objects to
> normal Zope3 folders. That is really a bad idea, and probably allowing
> that is a bug from the sqlos side.
> 
> Patches/testcases welcome!
> 

No, I am *not* trying to add sqlos objects to normal z3 folders. It's a
sqlos container and it's the simple Person example from the README.
If you want to reproduce the error, have a look at my attachement.

>> 
>> Regards,
>> Christian
>> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqlosperson.tgz
Type: application/x-compressed-tar
Size: 2837 bytes
Desc: not available
Url : http://codespeak.net/pipermail/z3-sqlos/attachments/20060121/a0e18564/attachment.bin 


More information about the z3-sqlos mailing list