[transactions] cleanup after the dbapi removal
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 11 Jun 2014 13:39:56 +0200
changeset 10360 1fdbe2ea63d8
parent 10359 8e4ba1028f55
child 10361 46d72f33c428
[transactions] cleanup after the dbapi removal * end req vs cnx dichotomy * Transaction takes a cnx at __init__ time * a couple of super calls are fixed Related to #3933480.
server/session.py
server/sources/native.py
transaction.py
--- a/server/session.py	Tue Jun 10 15:06:44 2014 +0200
+++ b/server/session.py	Wed Jun 11 13:39:56 2014 +0200
@@ -536,7 +536,7 @@
     # transaction api
 
     @_open_only
-    def undoable_transactions(self, ueid=None, req=None, **actionfilters):
+    def undoable_transactions(self, ueid=None, **actionfilters):
         """Return a list of undoable transaction objects by the connection's
         user, ordered by descendant transaction time.
 
@@ -559,26 +559,18 @@
           only searched in 'public' actions, unless a `public` argument is given
           and set to false.
         """
-        source = self.repo.system_source
-        txinfos = source.undoable_transactions(self, ueid, **actionfilters)
-        for txinfo in txinfos:
-            txinfo.req = req or self
-        return txinfos
+        return self.repo.system_source.undoable_transactions(self, ueid,
+                                                             **actionfilters)
 
     @_open_only
-    def transaction_info(self, txuuid, req=None):
+    def transaction_info(self, txuuid):
         """Return transaction object for the given uid.
 
         raise `NoSuchTransaction` if not found or if session's user is
         not allowed (eg not in managers group and the transaction
         doesn't belong to him).
         """
-        txinfo = self.repo.system_source.tx_info(self, txuuid)
-        if req:
-            txinfo.req = req
-        else:
-            txinfo.cnx = self
-        return txinfo
+        return self.repo.system_source.tx_info(self, txuuid)
 
     @_open_only
     def transaction_actions(self, txuuid, public=True):
--- a/server/sources/native.py	Tue Jun 10 15:06:44 2014 +0200
+++ b/server/sources/native.py	Wed Jun 11 13:39:56 2014 +0200
@@ -1022,11 +1022,11 @@
         with cnx.ensure_cnx_set:
             cu = self.doexec(cnx, sql, restr)
             # turn results into transaction objects
-            return [tx.Transaction(*args) for args in cu.fetchall()]
+            return [tx.Transaction(cnx, *args) for args in cu.fetchall()]
 
     def tx_info(self, cnx, txuuid):
         """See :class:`cubicweb.repoapi.Connection.transaction_info`"""
-        return tx.Transaction(txuuid, *self._tx_info(cnx, unicode(txuuid)))
+        return tx.Transaction(cnx, txuuid, *self._tx_info(cnx, unicode(txuuid)))
 
     def tx_actions(self, cnx, txuuid, public):
         """See :class:`cubicweb.repoapi.Connection.transaction_actions`"""
--- a/transaction.py	Tue Jun 10 15:06:44 2014 +0200
+++ b/transaction.py	Wed Jun 11 13:39:56 2014 +0200
@@ -36,27 +36,21 @@
     msg = _("there is no transaction #%s")
 
     def __init__(self, txuuid):
-        super(RepositoryError, self).__init__(txuuid)
+        super(NoSuchTransaction, self).__init__(txuuid)
         self.txuuid = txuuid
 
 class Transaction(object):
     """an undoable transaction"""
 
-    def __init__(self, uuid, time, ueid):
+    def __init__(self, cnx, uuid, time, ueid):
+        self.cnx = cnx
         self.uuid = uuid
         self.datetime = time
         self.user_eid = ueid
-        # should be set by the dbapi connection
-        self.req = None  # old style
-        self.cnx = None  # new style
 
     def _execute(self, *args, **kwargs):
         """execute a query using either the req or the cnx"""
-        if self.req is None:
-            execute = self.cnx.execute
-        else:
-            execute = self.req
-        return execute(*args, **kwargs)
+        return self.cnx.execute(*args, **kwargs)
 
 
     def __repr__(self):
@@ -67,8 +61,7 @@
         """return the user entity which has done the transaction,
         none if not found.
         """
-        return self._execute('Any X WHERE X eid %(x)s',
-                             {'x': self.user_eid}).get_entity(0, 0)
+        return self.cnx.find('CWUser', eid=self.user_eid).one()
 
     def actions_list(self, public=True):
         """return an ordered list of action effectued during that transaction
@@ -76,14 +69,11 @@
         if public is true, return only 'public' action, eg not ones triggered
         under the cover by hooks.
         """
-        if self.req is not None:
-            cnx = self.req.cnx
-        else:
-            cnx = self.cnx
-        return cnx.transaction_actions(self.uuid, public)
+        return self.cnx.transaction_actions(self.uuid, public)
 
 
 class AbstractAction(object):
+
     def __init__(self, action, public, order):
         self.action = action
         self.public = public
@@ -100,8 +90,9 @@
 
 
 class EntityAction(AbstractAction):
+
     def __init__(self, action, public, order, etype, eid, changes):
-        AbstractAction.__init__(self, action, public, order)
+        super(EntityAction, self).__init__(action, public, order)
         self.etype = etype
         self.eid = eid
         self.changes = changes
@@ -118,8 +109,9 @@
 
 
 class RelationAction(AbstractAction):
+
     def __init__(self, action, public, order, rtype, eidfrom, eidto):
-        AbstractAction.__init__(self, action, public, order)
+        super(RelationAction, self).__init__(action, public, order)
         self.rtype = rtype
         self.eid_from = eidfrom
         self.eid_to = eidto