[connection] remove the `mode` attribute
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 11 Jun 2014 17:58:19 +0200
changeset 10366 38c7598b5c61
parent 10365 21461f80f348
child 10367 8fc24ce5317e
[connection] remove the `mode` attribute It is now unused. While removing mode, we also drop some sqlserver-specific reconnection logic snippets. These had several downsides: * untested * partial coverage * done at the wrong level Related to #2919309.
misc/scripts/ldapuser2ldapfeed.py
misc/scripts/pyroforge2datafeed.py
server/querier.py
server/session.py
server/sources/native.py
server/test/unittest_repository.py
--- a/misc/scripts/ldapuser2ldapfeed.py	Wed Jun 11 17:14:32 2014 +0200
+++ b/misc/scripts/ldapuser2ldapfeed.py	Wed Jun 11 17:58:19 2014 +0200
@@ -31,8 +31,6 @@
 from cubicweb.server.edition import EditedEntity
 
 
-session.mode = 'write' # hold on the connections set
-
 print '******************** backport entity content ***************************'
 
 todelete = defaultdict(list)
--- a/misc/scripts/pyroforge2datafeed.py	Wed Jun 11 17:14:32 2014 +0200
+++ b/misc/scripts/pyroforge2datafeed.py	Wed Jun 11 17:58:19 2014 +0200
@@ -39,8 +39,6 @@
         ))
 
 
-session.mode = 'write' # hold on the connections set
-
 print '******************** backport entity content ***************************'
 
 from cubicweb.server import debugged
--- a/server/querier.py	Wed Jun 11 17:14:32 2014 +0200
+++ b/server/querier.py	Wed Jun 11 17:58:19 2014 +0200
@@ -580,9 +580,6 @@
         if rqlst.TYPE != 'select':
             if cnx.read_security:
                 check_no_password_selected(rqlst)
-            # write query, ensure connection's mode is 'write' so connections
-            # won't be released until commit/rollback
-            cnx.mode = 'write'
             cachekey = None
         else:
             if cnx.read_security:
--- a/server/session.py	Wed Jun 11 17:14:32 2014 +0200
+++ b/server/session.py	Wed Jun 11 17:58:19 2014 +0200
@@ -245,7 +245,6 @@
       read/write security is currently activated.
 
     """
-    mode = 'write'
     is_request = False
     hooks_in_progress = False
     is_repo_in_memory = True # bw compat
--- a/server/sources/native.py	Wed Jun 11 17:14:32 2014 +0200
+++ b/server/sources/native.py	Wed Jun 11 17:58:19 2014 +0200
@@ -553,25 +553,7 @@
                 self._cache[cachekey] = sql, qargs, cbs
         args = self.merge_args(args, qargs)
         assert isinstance(sql, basestring), repr(sql)
-        try:
-            cursor = self.doexec(cnx, sql, args)
-        except (self.OperationalError, self.InterfaceError):
-            if cnx.mode == 'write':
-                # do not attempt to reconnect if there has been some write
-                # during the transaction
-                raise
-            # FIXME: better detection of deconnection pb
-            self.warning("trying to reconnect")
-            cnx.cnxset.reconnect()
-            cursor = self.doexec(cnx, sql, args)
-        except self.DbapiError as exc:
-            # We get this one with pyodbc and SQL Server when connection was reset
-            if exc.args[0] == '08S01' and cnx.mode != 'write':
-                self.warning("trying to reconnect")
-                cnx.cnxset.reconnect()
-                cursor = self.doexec(cnx, sql, args)
-            else:
-                raise
+        cursor = self.doexec(cnx, sql, args)
         results = self.process_result(cursor, cnx, cbs)
         assert dbg_results(results)
         return results
@@ -829,18 +811,12 @@
 
     # system source interface #################################################
 
-    def _eid_type_source(self, cnx, eid, sql, _retry=True):
+    def _eid_type_source(self, cnx, eid, sql):
         try:
             res = self.doexec(cnx, sql).fetchone()
             if res is not None:
                 return res
-        except (self.OperationalError, self.InterfaceError):
-            if cnx.mode == 'read' and _retry:
-                self.warning("trying to reconnect (eid_type_source())")
-                cnx.cnxset.reconnect()
-                return self._eid_type_source(cnx, eid, sql, _retry=False)
         except Exception:
-            assert cnx.cnxset, 'connection has no connections set'
             self.exception('failed to query entities table for eid %s', eid)
         raise UnknownEid(eid)
 
@@ -1056,8 +1032,6 @@
         important note: while undoing of a transaction, only hooks in the
         'integrity', 'activeintegrity' and 'undo' categories are called.
         """
-        # set mode so connections set isn't released subsquently until commit/rollback
-        cnx.mode = 'write'
         errors = []
         cnx.transaction_data['undoing_uuid'] = txuuid
         with cnx.deny_all_hooks_but('integrity', 'activeintegrity', 'undo'):
--- a/server/test/unittest_repository.py	Wed Jun 11 17:14:32 2014 +0200
+++ b/server/test/unittest_repository.py	Wed Jun 11 17:58:19 2014 +0200
@@ -445,7 +445,6 @@
 
     def test_add_delete_info(self):
         with self.admin_access.repo_cnx() as cnx:
-            cnx.mode = 'write'
             entity = self.repo.vreg['etypes'].etype_class('Personne')(cnx)
             entity.eid = -1
             entity.complete = lambda x: None