[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.

authorAurelien Campeas <aurelien.campeas@logilab.fr>
changeset38c7598b5c61
branchdefault
phasepublic
hiddenno
parent revision#21461f80f348 [connection] remove ensure_cnx_set context manager uses
child revision#8fc24ce5317e [server/test] delete commented-out test
files modified by this revision
misc/scripts/ldapuser2ldapfeed.py
misc/scripts/pyroforge2datafeed.py
server/querier.py
server/session.py
server/sources/native.py
server/test/unittest_repository.py
# HG changeset patch
# User Aurelien Campeas <aurelien.campeas@logilab.fr>
# Date 1402502299 -7200
# Wed Jun 11 17:58:19 2014 +0200
# Node ID 38c7598b5c61f72fc8c0f8ca9e69b65e115600fa
# Parent 21461f80f348fb811d6709f098edf94f83681a8e
[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.

diff --git a/misc/scripts/ldapuser2ldapfeed.py b/misc/scripts/ldapuser2ldapfeed.py
@@ -29,12 +29,10 @@
1 
2  from datetime import datetime
3  from cubicweb.server.edition import EditedEntity
4 
5 
6 -session.mode = 'write' # hold on the connections set
7 -
8  print '******************** backport entity content ***************************'
9 
10  todelete = defaultdict(list)
11  extids = set()
12  duplicates = []
diff --git a/misc/scripts/pyroforge2datafeed.py b/misc/scripts/pyroforge2datafeed.py
@@ -37,12 +37,10 @@
13          'NarvalConditionExpression', 'Recipe',
14          # XXX TestConfig
15          ))
16 
17 
18 -session.mode = 'write' # hold on the connections set
19 -
20  print '******************** backport entity content ***************************'
21 
22  from cubicweb.server import debugged
23  todelete = {}
24  host = source.config['base-url'].split('://')[1]
diff --git a/server/querier.py b/server/querier.py
@@ -578,13 +578,10 @@
25                                                              eidkeys)
26              self._rql_cache[cachekey] = rqlst
27          if rqlst.TYPE != 'select':
28              if cnx.read_security:
29                  check_no_password_selected(rqlst)
30 -            # write query, ensure connection's mode is 'write' so connections
31 -            # won't be released until commit/rollback
32 -            cnx.mode = 'write'
33              cachekey = None
34          else:
35              if cnx.read_security:
36                  for select in rqlst.children:
37                      check_no_password_selected(select)
diff --git a/server/session.py b/server/session.py
@@ -243,11 +243,10 @@
38 
39        :attr:`read_security` and :attr:`write_security`, boolean flags telling if
40        read/write security is currently activated.
41 
42      """
43 -    mode = 'write'
44      is_request = False
45      hooks_in_progress = False
46      is_repo_in_memory = True # bw compat
47 
48      def __init__(self, session):
diff --git a/server/sources/native.py b/server/sources/native.py
@@ -551,29 +551,11 @@
49                  self.cache_miss += 1
50                  sql, qargs, cbs = self._rql_sqlgen.generate(union, args, varmap)
51                  self._cache[cachekey] = sql, qargs, cbs
52          args = self.merge_args(args, qargs)
53          assert isinstance(sql, basestring), repr(sql)
54 -        try:
55 -            cursor = self.doexec(cnx, sql, args)
56 -        except (self.OperationalError, self.InterfaceError):
57 -            if cnx.mode == 'write':
58 -                # do not attempt to reconnect if there has been some write
59 -                # during the transaction
60 -                raise
61 -            # FIXME: better detection of deconnection pb
62 -            self.warning("trying to reconnect")
63 -            cnx.cnxset.reconnect()
64 -            cursor = self.doexec(cnx, sql, args)
65 -        except self.DbapiError as exc:
66 -            # We get this one with pyodbc and SQL Server when connection was reset
67 -            if exc.args[0] == '08S01' and cnx.mode != 'write':
68 -                self.warning("trying to reconnect")
69 -                cnx.cnxset.reconnect()
70 -                cursor = self.doexec(cnx, sql, args)
71 -            else:
72 -                raise
73 +        cursor = self.doexec(cnx, sql, args)
74          results = self.process_result(cursor, cnx, cbs)
75          assert dbg_results(results)
76          return results
77 
78      @contextmanager
@@ -827,22 +809,16 @@
79          cursor = LogCursor(cnx.cnxset.cu)
80          self.dbhelper.drop_index(cursor, table, column, unique)
81 
82      # system source interface #################################################
83 
84 -    def _eid_type_source(self, cnx, eid, sql, _retry=True):
85 +    def _eid_type_source(self, cnx, eid, sql):
86          try:
87              res = self.doexec(cnx, sql).fetchone()
88              if res is not None:
89                  return res
90 -        except (self.OperationalError, self.InterfaceError):
91 -            if cnx.mode == 'read' and _retry:
92 -                self.warning("trying to reconnect (eid_type_source())")
93 -                cnx.cnxset.reconnect()
94 -                return self._eid_type_source(cnx, eid, sql, _retry=False)
95          except Exception:
96 -            assert cnx.cnxset, 'connection has no connections set'
97              self.exception('failed to query entities table for eid %s', eid)
98          raise UnknownEid(eid)
99 
100      def eid_type_source(self, cnx, eid): # pylint: disable=E0202
101          """return a tuple (type, source, extid) for the entity with id <eid>"""
@@ -1054,12 +1030,10 @@
102          """See :class:`cubicweb.repoapi.Connection.undo_transaction`
103 
104          important note: while undoing of a transaction, only hooks in the
105          'integrity', 'activeintegrity' and 'undo' categories are called.
106          """
107 -        # set mode so connections set isn't released subsquently until commit/rollback
108 -        cnx.mode = 'write'
109          errors = []
110          cnx.transaction_data['undoing_uuid'] = txuuid
111          with cnx.deny_all_hooks_but('integrity', 'activeintegrity', 'undo'):
112              with cnx.security_enabled(read=False):
113                  for action in reversed(self.tx_actions(cnx, txuuid, False)):
diff --git a/server/test/unittest_repository.py b/server/test/unittest_repository.py
@@ -443,11 +443,10 @@
114          with self.admin_access.repo_cnx() as cnx:
115              self.assertRaises(UnknownEid, self.repo.type_from_eid, -2, cnx)
116 
117      def test_add_delete_info(self):
118          with self.admin_access.repo_cnx() as cnx:
119 -            cnx.mode = 'write'
120              entity = self.repo.vreg['etypes'].etype_class('Personne')(cnx)
121              entity.eid = -1
122              entity.complete = lambda x: None
123              self.repo.add_info(cnx, entity, self.repo.system_source)
124              cu = cnx.system_sql('SELECT * FROM entities WHERE eid = -1')