# HG changeset patch # User Pierre-Yves David # Date 1363974588 -3600 # Node ID 1672502ac204822b5549d328b68092cf921ef5bb # Parent 3d105e270abc742ae4b7489c9e035b1cf833fe35 [transaction] move RQLRewriter in Transaction This remove the last ``AttributeError`` magic. The ``RQLRewriter`` needs a Session. Its reset is handled in ``Session`` code to handle that diff -r 3d105e270abc -r 1672502ac204 server/session.py --- a/server/session.py Fri Mar 22 18:38:56 2013 +0100 +++ b/server/session.py Fri Mar 22 18:49:48 2013 +0100 @@ -196,7 +196,7 @@ """ - def __init__(self, txid, mode='read'): + def __init__(self, txid, mode, rewriter): #: transaction unique id self.transactionid = txid #: reentrance handling @@ -225,6 +225,9 @@ self.read_security = DEFAULT_SECURITY self.write_security = DEFAULT_SECURITY + # RQLRewriter are not thread safe + self._rewriter = rewriter + def clear(self): """reset internal data""" @@ -406,7 +409,8 @@ try: self.__threaddata.txdata = self._tx_data[txid] except KeyError: - tx = Transaction(txid, self.default_mode) + rewriter = RQLRewriter(self) + tx = Transaction(txid, self.default_mode, rewriter) self.__threaddata.txdata = self._tx_data[txid] = tx @property @@ -1021,10 +1025,7 @@ def _clear_tx_storage(self, txstore): txstore.clear() - try: - del txstore._rewriter - except AttributeError: - pass + txstore._rewriter = RQLRewriter(self) def commit(self, free_cnxset=True, reset_pool=None): """commit the current session's transaction""" @@ -1220,11 +1221,7 @@ @property def rql_rewriter(self): # in thread local storage since the rewriter isn't thread safe - try: - return self._threaddata._rewriter - except AttributeError: - self._threaddata._rewriter = RQLRewriter(self) - return self._threaddata._rewriter + return self._threaddata._rewriter # deprecated ###############################################################