Deprecation problem and ConnectionStateError, was: Re: [ZODB-Dev] Span transaction over several threads

Tim Peters tim at zope.com
Thu Sep 9 09:32:52 EDT 2004


[Diez Roggisch]
> Ok, found a solution for that - I can call
>
> setLocalTransaction()
>
> on the connection. But that method is deprecated, instead I shall use the
> txn_mgr argument to DB.open().
>
> I'd love to do that, but the docs on that are sparse -

You mean unlike the copious docs for setLocalTransaction <wink>?

> what would I have to pass to DB.open() to have the same thread-spanning
> transactional behaviour?

See NEWS.txt, under the "ZODB3 3.3 alpha 3" section.  In short, you create
an instance of transaction.TransactionManager and pass it to open().  Hmm!
The example there is wrong:  TransactionManager doesn't have a commit()
method.  Where it says:

    >>> tm.commit()

it should say:

    >>> tm.get().commit()

There's also Jeremy's Wiki writeup:

    http://zope.org/Wikis/ZODB/ReviseTransactionAPI


> Another side-effect of setLocalTransaction() is that when I try to open a
> not-yet existing DB,  I get
>
> ConnectionStateError: Cannot close a connection joined to a transaction

Sorry, I don't know what this means.  Post code if you care!  Here's my best
guess at what that meant, and it works for me:

>>> import ZODB
>>> from ZODB.FileStorage import FileStorage
>>> st = FileStorage('DoesNotExist.fs')
>>> db = ZODB.DB(st)
>>> cn = db.open()
>>> cn.setLocalTransaction()
C:\code\ZODB3.3\src\ZODB\Connection.py:282: DeprecationWarning:
setLocalTransaction() is deprecated. Use the txn_mgr arg
ument to DB.open() instead.
  DeprecationWarning)
<transaction._manager.TransactionManager object at 0x009EE6D0>
>>> rt = cn.root()
>>> rt['a'] = 1
>>> cn.getTransaction().commit()
C:\code\ZODB3.3\src\ZODB\Connection.py:268: DeprecationWarning:
getTransaction() is deprecated. Use the txn_mgr argument
 to DB.open() instead.
  DeprecationWarning)
>>> cn.close()
>>>

> If I comment things out,

Since you didn't show any code, your demands on the reader's telepathy have
gone beyond even wishful thinking now <wink>.

> everything works as expected. Then I can uncomment the
> setLocalTransaction and from there on opening the db works
> just fine.
>
> The latter problem is more annoying, if there is no solution I guess I
> can code around it - but I'd prefer of course to have things working
> properly.

setLocalTransaction() is deprecated anyway.

> python is 2.3.4, ZODB is 3.3b2.

Same Python, but I was using current ZODB trunk.  I didn't change anything
having to do with setLocalTransaction() since 3.3b2, though.



More information about the ZODB-Dev mailing list