server/session.py
changeset 8805 d91285fe7242
parent 8790 c3fc17d79e85
child 8806 8ca4b323223c
equal deleted inserted replaced
8804:21770f74a078 8805:d91285fe7242
   150 
   150 
   151     Holds all transaction related data
   151     Holds all transaction related data
   152 
   152 
   153     Database connections resource:
   153     Database connections resource:
   154 
   154 
       
   155       :attr:`running_dbapi_query`, boolean flag telling if the executing query
       
   156       is coming from a dbapi connection or is a query from within the repository
       
   157 
   155       :attr:`cnxset`, the connections set to use to execute queries on sources.
   158       :attr:`cnxset`, the connections set to use to execute queries on sources.
   156       If the transaction is read only, the connection set may be freed between
   159       If the transaction is read only, the connection set may be freed between
   157       actual query. This allows multiple transaction with a reasonable low
   160       actual query. This allows multiple transaction with a reasonable low
   158       connection set pool size. control mechanism is detailed below
   161       connection set pool size. control mechanism is detailed below
   159 
   162 
   204 
   207 
   205         #: connection handling mode
   208         #: connection handling mode
   206         self.mode = mode
   209         self.mode = mode
   207         #: connection set used to execute queries on sources
   210         #: connection set used to execute queries on sources
   208         self.cnxset = None
   211         self.cnxset = None
       
   212         #: is this transaction from a client or internal to the repo
       
   213         self.running_dbapi_query = True
   209 
   214 
   210         #: dict containing arbitrary data cleared at the end of the transaction
   215         #: dict containing arbitrary data cleared at the end of the transaction
   211         self.data = {}
   216         self.data = {}
   212         #: ordered list of operations to be processed on commit/rollback
   217         #: ordered list of operations to be processed on commit/rollback
   213         self.pending_operations = []
   218         self.pending_operations = []
   784         of this to change security settings.
   789         of this to change security settings.
   785         """
   790         """
   786         tx = self._tx
   791         tx = self._tx
   787         oldmode = tx.read_security
   792         oldmode = tx.read_security
   788         tx.read_security = activated
   793         tx.read_security = activated
   789         # dbapi_query used to detect hooks triggered by a 'dbapi' query (eg not
   794         # running_dbapi_query used to detect hooks triggered by a 'dbapi' query
   790         # issued on the session). This is tricky since we the execution model of
   795         # (eg not issued on the session). This is tricky since we the execution
   791         # a (write) user query is:
   796         # model of a (write) user query is:
   792         #
   797         #
   793         # repository.execute (security enabled)
   798         # repository.execute (security enabled)
   794         #  \-> querier.execute
   799         #  \-> querier.execute
   795         #       \-> repo.glob_xxx (add/update/delete entity/relation)
   800         #       \-> repo.glob_xxx (add/update/delete entity/relation)
   796         #            \-> deactivate security before calling hooks
   801         #            \-> deactivate security before calling hooks
   799         #
   804         #
   800         # so we can't rely on simply checking session.read_security, but
   805         # so we can't rely on simply checking session.read_security, but
   801         # recalling the first transition from DEFAULT_SECURITY to something
   806         # recalling the first transition from DEFAULT_SECURITY to something
   802         # else (False actually) is not perfect but should be enough
   807         # else (False actually) is not perfect but should be enough
   803         #
   808         #
   804         # also reset dbapi_query to true when we go back to DEFAULT_SECURITY
   809         # also reset running_dbapi_query to true when we go back to
   805         tx.dbapi_query = (oldmode is DEFAULT_SECURITY
   810         # DEFAULT_SECURITY
       
   811         tx.running_dbapi_query = (oldmode is DEFAULT_SECURITY
   806                                or activated is DEFAULT_SECURITY)
   812                                or activated is DEFAULT_SECURITY)
   807         return oldmode
   813         return oldmode
   808 
   814 
   809     write_security = tx_attr('write_security')
   815     write_security = tx_attr('write_security')
   810 
   816 
   818         tx = self._tx
   824         tx = self._tx
   819         oldmode = tx.write_security
   825         oldmode = tx.write_security
   820         tx.write_security = activated
   826         tx.write_security = activated
   821         return oldmode
   827         return oldmode
   822 
   828 
   823     @property
   829     running_dbapi_query = tx_attr('running_dbapi_query')
   824     def running_dbapi_query(self):
       
   825         """return a boolean telling if it's triggered by a db-api query or by
       
   826         a session query.
       
   827 
       
   828         To be used in hooks, else may have a wrong value.
       
   829         """
       
   830         return getattr(self._tx, 'dbapi_query', True)
       
   831 
   830 
   832     # hooks activation control #################################################
   831     # hooks activation control #################################################
   833     # all hooks should be activated during normal execution
   832     # all hooks should be activated during normal execution
   834 
   833 
   835     def allow_all_hooks_but(self, *categories):
   834     def allow_all_hooks_but(self, *categories):