Simplify and fix _cw.drop_entity_cache
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 24 Nov 2016 15:36:26 +0100
changeset 11892 08cf02efc7ce
parent 11891 67185e65f020
child 11897 2ceb0bfa4b3f
Simplify and fix _cw.drop_entity_cache * it's never called with an eid as argument, beside in a useless case in test (removed) * the only place where it's called from outside the tests is in full-text reindexation in server.checkintegrity: we could removed the request implementation and move it in unittest_rset, byt I decided to keep it for consistency with all other entity cache handling methods * get back a fix from Julien Cristau for the connection's implementation, quoting is commit message: When removing an entity from the transaction's cache, clear the entity's own cache May avoid issues where an entity object is still accessible somewhere else (e.g. an operation) after dropping it from the transaction's cache, with a stale attribute or relation cache.
cubicweb/server/session.py
cubicweb/test/unittest_rset.py
cubicweb/web/request.py
--- a/cubicweb/server/session.py	Fri Nov 18 17:50:56 2016 +0100
+++ b/cubicweb/server/session.py	Thu Nov 24 15:36:26 2016 +0100
@@ -504,14 +504,11 @@
         return self.transaction_data.get('ecache', {}).values()
 
     @_open_only
-    def drop_entity_cache(self, eid=None):
-        """drop entity from the cache
-
-        If eid is None, the whole cache is dropped"""
-        if eid is None:
-            self.transaction_data.pop('ecache', None)
-        else:
-            del self.transaction_data['ecache'][eid]
+    def drop_entity_cache(self):
+        """Drop the whole entity cache."""
+        for entity in self.cached_entities():
+            entity.cw_clear_all_caches()
+        self.transaction_data.pop('ecache', None)
 
     # relations handling #######################################################
 
--- a/cubicweb/test/unittest_rset.py	Fri Nov 18 17:50:56 2016 +0100
+++ b/cubicweb/test/unittest_rset.py	Thu Nov 24 15:36:26 2016 +0100
@@ -156,8 +156,6 @@
 
     def test_limit_2(self):
         with self.admin_access.web_request() as req:
-            # drop user from cache for the sake of this test
-            req.drop_entity_cache(req.user.eid)
             rs = req.execute('Any E,U WHERE E is CWEType, E created_by U')
             # get entity on row 9. This will fill its created_by relation cache,
             # with cwuser on row 9 as well
--- a/cubicweb/web/request.py	Fri Nov 18 17:50:56 2016 +0100
+++ b/cubicweb/web/request.py	Thu Nov 24 15:36:26 2016 +0100
@@ -1009,11 +1009,8 @@
     def cached_entities(self):
         return self.transaction_data.get('req_ecache', {}).values()
 
-    def drop_entity_cache(self, eid=None):
-        if eid is None:
-            self.transaction_data.pop('req_ecache', None)
-        else:
-            del self.transaction_data['req_ecache'][eid]
+    def drop_entity_cache(self):
+        self.transaction_data.pop('req_ecache', None)
 
 
 CubicWebRequestBase = ConnectionCubicWebRequestBase