# HG changeset patch # User Pierre-Yves David # Date 1363979149 -3600 # Node ID 4e72b78ea5aa57c78b8b92b9cd0e722ea9125b79 # Parent cdb261bd36ac25ec1e96cf24d4a7054bf79ac7e5 [session] split session creation from default session assignation This is the first step for more independence for Transaction. diff -r cdb261bd36ac -r 4e72b78ea5aa server/session.py --- a/server/session.py Fri Mar 22 20:04:43 2013 +0100 +++ b/server/session.py Fri Mar 22 20:05:49 2013 +0100 @@ -394,18 +394,26 @@ return '' % ( unicode(self.user.login), self.id, id(self)) + def get_tx(self, txid): + """return the transaction attached to this session + + Transaction is created if necessary""" + with self._lock: # no transaction exist with the same id + try: + tx = self._txs[txid] + except KeyError: + rewriter = RQLRewriter(self) + tx = Transaction(txid, self.default_mode, rewriter) + self._txs[txid] = tx + return tx + def set_tx(self, txid=None): """set the default transaction of the current thread to Transaction is created if necessary""" if txid is None: txid = threading.currentThread().getName() - try: - self.__threaddata.tx = self._txs[txid] - except KeyError: - rewriter = RQLRewriter(self) - tx = Transaction(txid, self.default_mode, rewriter) - self.__threaddata.tx = self._txs[txid] = tx + self.__threaddata.tx = self.get_tx(txid) @property def _tx(self):