[dbapi] refactor so that cw 3.8.6 can still speak with a 3.8.5 server stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 02 Jul 2010 10:38:56 +0200
branchstable
changeset 5859 3da3574fe397
parent 5857 1a24c62aefc5
child 5862 980db7f775e2
[dbapi] refactor so that cw 3.8.6 can still speak with a 3.8.5 server
dbapi.py
--- a/dbapi.py	Wed Jun 23 13:54:02 2010 +0200
+++ b/dbapi.py	Fri Jul 02 10:38:56 2010 +0200
@@ -443,7 +443,7 @@
                  DeprecationWarning, stacklevel=2)
         # XXX use named argument for build_descr in case repo is < 3.8
         rset = self._repo.execute(self._sessid, rql, args,
-                                  build_descr=build_descr, txid=self._txid())
+                                  build_descr=build_descr, **self._txid())
         rset.req = self.req
         return rset
 
@@ -482,6 +482,10 @@
         if cnxprops and cnxprops.log_queries:
             self.executed_queries = []
             self.cursor_class = LogCursor
+        if self._cnxtype == 'pyro':
+            # check client/server compat
+            if self._repo.get_versions()['cubicweb'] < (3, 8, 6):
+                self._txid = lambda cursor=None: {}
 
     def __repr__(self):
         if self.anonymous_connection:
@@ -499,7 +503,8 @@
             return False #propagate the exception
 
     def _txid(self, cursor=None): # XXX could now handle various isolation level!
-        return currentThread().getName()
+        # return a dict as bw compat trick
+        return {'txid': currentThread().getName()}
 
     def request(self):
         return DBAPIRequest(self.vreg, DBAPISession(self))
@@ -636,7 +641,7 @@
     def describe(self, eid):
         if self._closed is not None:
             raise ProgrammingError('Closed connection')
-        return self._repo.describe(self.sessionid, eid, txid=self._txid())
+        return self._repo.describe(self.sessionid, eid, **self._txid())
 
     def close(self):
         """Close the connection now (rather than whenever __del__ is called).
@@ -649,7 +654,7 @@
         """
         if self._closed:
             raise ProgrammingError('Connection is already closed')
-        self._repo.close(self.sessionid, txid=self._txid())
+        self._repo.close(self.sessionid, **self._txid())
         del self._repo # necessary for proper garbage collection
         self._closed = 1
 
@@ -663,7 +668,7 @@
         """
         if not self._closed is None:
             raise ProgrammingError('Connection is already closed')
-        return self._repo.commit(self.sessionid, txid=self._txid())
+        return self._repo.commit(self.sessionid, **self._txid())
 
     def rollback(self):
         """This method is optional since not all databases provide transaction
@@ -676,7 +681,7 @@
         """
         if not self._closed is None:
             raise ProgrammingError('Connection is already closed')
-        self._repo.rollback(self.sessionid, txid=self._txid())
+        self._repo.rollback(self.sessionid, **self._txid())
 
     def cursor(self, req=None):
         """Return a new Cursor Object using the connection.
@@ -716,8 +721,8 @@
           only searched in 'public' actions, unless a `public` argument is given
           and set to false.
         """
+        actionfilters.update(self._txid())
         txinfos = self._repo.undoable_transactions(self.sessionid, ueid,
-                                                   txid=self._txid(),
                                                    **actionfilters)
         if req is None:
             req = self.request()
@@ -733,7 +738,7 @@
         him).
         """
         txinfo = self._repo.transaction_info(self.sessionid, txuuid,
-                                             txid=self._txid())
+                                             **self._txid())
         if req is None:
             req = self.request()
         txinfo.req = req
@@ -750,7 +755,7 @@
         transaction doesn't belong to him).
         """
         return self._repo.transaction_actions(self.sessionid, txuuid, public,
-                                              txid=self._txid())
+                                              **self._txid())
 
     def undo_transaction(self, txuuid):
         """Undo the given transaction. Return potential restoration errors.
@@ -760,4 +765,4 @@
         him).
         """
         return self._repo.undo_transaction(self.sessionid, txuuid,
-                                           txid=self._txid())
+                                           **self._txid())