[transaction] initialize dbapi_request in __init__

There is not reason to have it implicitly declared.

The attribute is renamed to match its public name.

authorPierre-Yves David <pierre-yves.david@logilab.fr>
changeseta0470b8c2f23
branchdefault
phasedraft
hiddenyes
parent revision#1a4ac6667f13 [whatsnew] notify drop of deprecated code
child revision#26131c5c4dad [session/transaction] move read_security subtlety in transaction
files modified by this revision
server/session.py
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1364224082 -3600
# Mon Mar 25 16:08:02 2013 +0100
# Node ID a0470b8c2f23c6a6b8478ce37ec18c00ce69d557
# Parent 1a4ac6667f131f70fc2351f82cbfabe2baf4293b
[transaction] initialize dbapi_request in __init__

There is not reason to have it implicitly declared.

The attribute is renamed to match its public name.

diff --git a/server/session.py b/server/session.py
@@ -150,10 +150,13 @@
1 
2      Holds all transaction related data
3 
4      Database connections resource:
5 
6 +      :attr:`running_dbapi_query`, boolean flag telling if the executing query
7 +      is coming from a dbapi connection or is a query from within the repository
8 +
9        :attr:`cnxset`, the connections set to use to execute queries on sources.
10        If the transaction is read only, the connection set may be freed between
11        actual query. This allows multiple transaction with a reasonable low
12        connection set pool size. control mechanism is detailed below
13 
@@ -204,10 +207,12 @@
14 
15          #: connection handling mode
16          self.mode = mode
17          #: connection set used to execute queries on sources
18          self.cnxset = None
19 +        #: is this transaction from a client or internal to the repo
20 +        self.running_dbapi_query = True
21 
22          #: dict containing arbitrary data cleared at the end of the transaction
23          self.data = {}
24          #: ordered list of operations to be processed on commit/rollback
25          self.pending_operations = []
@@ -784,13 +789,13 @@
26          of this to change security settings.
27          """
28          tx = self._tx
29          oldmode = tx.read_security
30          tx.read_security = activated
31 -        # dbapi_query used to detect hooks triggered by a 'dbapi' query (eg not
32 -        # issued on the session). This is tricky since we the execution model of
33 -        # a (write) user query is:
34 +        # running_dbapi_query used to detect hooks triggered by a 'dbapi' query
35 +        # (eg not issued on the session). This is tricky since we the execution
36 +        # model of a (write) user query is:
37          #
38          # repository.execute (security enabled)
39          #  \-> querier.execute
40          #       \-> repo.glob_xxx (add/update/delete entity/relation)
41          #            \-> deactivate security before calling hooks
@@ -799,12 +804,13 @@
42          #
43          # so we can't rely on simply checking session.read_security, but
44          # recalling the first transition from DEFAULT_SECURITY to something
45          # else (False actually) is not perfect but should be enough
46          #
47 -        # also reset dbapi_query to true when we go back to DEFAULT_SECURITY
48 -        tx.dbapi_query = (oldmode is DEFAULT_SECURITY
49 +        # also reset running_dbapi_query to true when we go back to
50 +        # DEFAULT_SECURITY
51 +        tx.running_dbapi_query = (oldmode is DEFAULT_SECURITY
52                                 or activated is DEFAULT_SECURITY)
53          return oldmode
54 
55      write_security = tx_attr('write_security')
56 
@@ -818,18 +824,11 @@
57          tx = self._tx
58          oldmode = tx.write_security
59          tx.write_security = activated
60          return oldmode
61 
62 -    @property
63 -    def running_dbapi_query(self):
64 -        """return a boolean telling if it's triggered by a db-api query or by
65 -        a session query.
66 -
67 -        To be used in hooks, else may have a wrong value.
68 -        """
69 -        return getattr(self._tx, 'dbapi_query', True)
70 +    running_dbapi_query = tx_attr('running_dbapi_query')
71 
72      # hooks activation control #################################################
73      # all hooks should be activated during normal execution
74 
75      def allow_all_hooks_but(self, *categories):