[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.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset2b398e58ea73
branchdefault
phasepublic
hiddenno
parent revision#a05a698a12af [hook] don't open-code Connection.entity_cache
child revision#09ac2645139c update repo sources on update of source's entities .url attribute, #b924635e10f8 [web] remove PropertySheet._cache, #259c8335d097 unormalize source's name to avoid logging errors, #0a4f10b791ab [tests] Fix config.repository() in tests, #6a045c244671 avoid propagation of NoSelectableObject in some case of inlined relations / permissions, #cae4061d9ed1 [migration] don't attempt to backport values on renaming of a computed relation, #1ab79c435fae consider .do_fti flag in index_entity method, #be7665d7d947 [migration] don't attempt to backport values on renaming of a computed relation, #62a24aa61559 ensure there are no NOT NULL constraint in the database before attempting to remove data for a removed inlined relation definition, #959966bcfc42 [web] remove PropertySheet._cache, #b311c8de441b consider .do_fti flag in index_entity method, #ae42a793cf94 [views] fix ProcessInformationView: SESSION_MANAGER can be None (closes #5753280), #563b1480a1da Fix config.repository() in tests, #b0fde3192814 [views] fix ProcessInformationView: SESSION_MANAGER can be None (closes #5753280), #4165128943b7 Copy read permissions on ComputedRelation rdefs
files modified by this revision
hooks/security.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1437495451 -7200
# Tue Jul 21 18:17:31 2015 +0200
# Node ID 2b398e58ea7351ceb94389ceacb7a0d091f2da6d
# Parent a05a698a12af2896245345683aef86ee0aa8e7de
[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.

diff --git a/hooks/security.py b/hooks/security.py
@@ -144,11 +144,14 @@
1      assert rschema.inlined
2      try:
3          entity = cnx.entity_cache(eid)
4      except KeyError:
5          return False
6 -    return rschema.type in entity.cw_edited.skip_security
7 +    edited = getattr(entity, 'cw_edited', None)
8 +    if edited is None:
9 +        return False
10 +    return rschema.type in edited.skip_security
11 
12 
13  class BeforeAddRelationSecurityHook(SecurityHook):
14      __regid__ = 'securitybeforeaddrelation'
15      events = ('before_add_relation',)