[hook] remove assumption about entity cache vs cw_edited
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 21 Jul 2015 18:17:31 +0200
changeset 10548 2b398e58ea73
parent 10547 a05a698a12af
child 10631 1ab79c435fae
[hook] remove assumption about entity cache vs cw_edited We were assuming that if an entity is in the connection's cache, it has a cw_edited attribute. This doesn't seem to always be the case. At least in cubicweb 3.21, merging the web and repo-side caches makes this more likely, but Denis says he's also seen this on 3.20.
hooks/security.py
--- a/hooks/security.py	Tue Jul 21 18:09:12 2015 +0200
+++ b/hooks/security.py	Tue Jul 21 18:17:31 2015 +0200
@@ -146,7 +146,10 @@
         entity = cnx.entity_cache(eid)
     except KeyError:
         return False
-    return rschema.type in entity.cw_edited.skip_security
+    edited = getattr(entity, 'cw_edited', None)
+    if edited is None:
+        return False
+    return rschema.type in edited.skip_security
 
 
 class BeforeAddRelationSecurityHook(SecurityHook):