server/session.py
changeset 8769 1672502ac204
parent 8768 3d105e270abc
child 8770 2005dcc6150e
--- 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 ###############################################################