Commit 6f8892cc authored by Kirill Smelkov's avatar Kirill Smelkov

test/gen_testdata: Fix for ZODB4

This fixes 0b6f99da (test/gen_testdata: Fix for ZODB5 > 5.5.1 + preserve
database compatibility with ZODB3/py2) which broke that program on ZODB4
because there is no TransactionMetaData:

    (neo) (z4-dev) (g.env) kirr@deca:~/src/neo/src/lab.nexedi.com/kirr/neo/go/zodb/btree$ go generate
    Traceback (most recent call last):
      File "./testdata/gen-testdata", line 26, in <module>
        from zodbtools.test.gen_testdata import run_with_zodb4py2_compat
      File "/home/kirr/src/wendelin/z/zodbtools/zodbtools/test/gen_testdata.py", line 42, in <module>
        from ZODB.Connection import TransactionMetaData
    ImportError: cannot import name TransactionMetaData
    btree_test.go:22: running "./testdata/gen-testdata": exit status 1

-> Fix it, similarly to how treegen.py handles this situation in WCFS:

wendelin.core@4300d88a
https://lab.nexedi.com/kirr/wendelin.core/blob/57be0126/wcfs/internal/xbtree/xbtreetest/treegen.py
parent aa7e1966
......@@ -39,7 +39,8 @@
from ZODB.FileStorage import FileStorage
from ZODB import DB
from ZODB.Connection import TransactionMetaData
import ZODB.Connection
TransactionMetaData = getattr(ZODB.Connection, 'TransactionMetaData', None) # not on ZODB4
from ZODB.POSException import UndoError
from persistent import Persistent
import transaction
......@@ -243,7 +244,10 @@ def _gen_testdb(outfs_path, zext):
u"delete %i\nalpha beta gamma'delta\"lambda\n\nqqq ..." % i,
ext("delete %s" % unpack64(obj._p_oid)))
# at low level stor requires ZODB.IStorageTransactionMetaData not txn (ITransaction)
if TransactionMetaData is not None:
txn_stormeta = TransactionMetaData(txn.user, txn.description, txn.extension)
else:
txn_stormeta = txn # ZODB4
stor.tpc_begin(txn_stormeta)
stor.deleteObject(obj._p_oid, obj_tid_lastchange, txn_stormeta)
stor.tpc_vote(txn_stormeta)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment