[Zope-dev] The Application object
Jeff K. Hoffman
jeff.hoffman@goingv.com
Mon, 17 Jul 2000 13:49:15 -0400 (EDT)
On Mon, 17 Jul 2000, Shane Hathaway wrote:
> "Jeff K. Hoffman" wrote:
>
> > Do I need to commit or abort even if I don't make changes to the
> > application object? The only thing I need it for is to get to the
> > Control_Panel; I am instantiating ZClass instances in the constructor of a
> > Python class, i.e.:
> >
> > class MyClass:
> >
> > def __init__(self, id, title=''):
> > import Zope
> > app = Zope.app()
> >
> > ob = app.Control_Panel.Products.MyProduct.MyZClass('newId')
> > ob.id = 'newId'
> >
> > self._setObject('newId', ob)
> >
> > # Do I need a get_transaction().abort() here? Will that not abort
> > # the wrong transaction?
> >
> > app._p_jar.close()
> >
>
> Hmm... you're creating an object in a separate connection (I would call
> get_transaction().abort() just to be on the safe side...) then copying
> that object over to the existing connection. This will probably work,
> but I wouldn't be surprised to see thorny bugs appear.
I have just hit one such thorny bug. Oh well. :-)
> If you could instead get a handle to the existing connection, you'd be
> following standard practice. You probably have a manage_addMyClass()
> method, don't you? The "self" argument provided to that method is
> already connected to the database. self.getPhysicalRoot() will give
> you the equivalent of the app object. Then just change your
> constructor this way:
>
> > def __init__(self, app, id, title=''):
> > ob = app.Control_Panel.Products.MyProduct.MyZClass('newId')
> > ob.id = 'newId'
> >
> > self._setObject('newId', ob)
Yeah, I was there, and that worked great. Then, I started implementing my
__setstate__ method to "upgrade" old instances of my python class. I need
to access the connection from here, too, and this is where the trouble
begins.
AFAICT, I cannot call self.getPhysicalRoot() from __setstate__, for the
same reason I can't call it from __init__. I can get by the __init__
problem by passing app in as an argument from manage_addMyProduct(). I can
find no such solution for __setstate__.
> Best of luck!
>
> Shane
All of my efforts are progressing towards one goal: How do I upgrade
existing instances of a ZClass? Since I could find no __setstate__ method
for ZClasses, I re-wrote the containing class as a Python class and
figured I could leverage __setstate__ there, instantiating the subordinate
ZClasses when required.
No such luck.
I am going to spend a little more time working on this. If I can't find a
solution, I may drop ZClasses altogether and move all my code to Python. I
had hoped not to do this, because my web guys can work with ZClasses but
have no clue where to begin with a Python Product.
I may just have to take total ownership of the code, as much as I dislike
the idea, if I can find no other solution.
--Jeff
---
Jeff K. Hoffman 704.849.0731 x108
Chief Technology Officer mailto:jeff.hoffman@goingv.com
Going Virtual, L.L.C. http://www.goingv.com/