[server] hold connection to the db in tx_actions
We can be called without a cnxset (e.g. from repoapi).
--- a/server/sources/native.py Mon Sep 15 17:23:22 2014 +0200
+++ b/server/sources/native.py Mon Sep 15 10:06:07 2014 +0200
@@ -1017,14 +1017,16 @@
sql = self.sqlgen.select('tx_entity_actions', restr,
('txa_action', 'txa_public', 'txa_order',
'etype', 'eid', 'changes'))
- cu = self.doexec(cnx, sql, restr)
- actions = [tx.EntityAction(a,p,o,et,e,c and loads(self.binary_to_str(c)))
- for a,p,o,et,e,c in cu.fetchall()]
+ with cnx.ensure_cnx_set:
+ cu = self.doexec(cnx, sql, restr)
+ actions = [tx.EntityAction(a,p,o,et,e,c and loads(self.binary_to_str(c)))
+ for a,p,o,et,e,c in cu.fetchall()]
sql = self.sqlgen.select('tx_relation_actions', restr,
('txa_action', 'txa_public', 'txa_order',
'rtype', 'eid_from', 'eid_to'))
- cu = self.doexec(cnx, sql, restr)
- actions += [tx.RelationAction(*args) for args in cu.fetchall()]
+ with cnx.ensure_cnx_set:
+ cu = self.doexec(cnx, sql, restr)
+ actions += [tx.RelationAction(*args) for args in cu.fetchall()]
return sorted(actions, key=lambda x: x.order)
def undo_transaction(self, cnx, txuuid):
--- a/server/test/unittest_undo.py Mon Sep 15 17:23:22 2014 +0200
+++ b/server/test/unittest_undo.py Mon Sep 15 10:06:07 2014 +0200
@@ -75,6 +75,8 @@
self.assertTrue(self.txuuid)
# test transaction api
with self.admin_access.client_cnx() as cnx:
+ tx_actions = cnx.transaction_actions(self.txuuid)
+ self.assertEqual(len(tx_actions), 2, tx_actions)
self.assertRaises(NoSuchTransaction,
cnx.transaction_info, 'hop')
self.assertRaises(NoSuchTransaction,