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

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)

Best of luck!


Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to