Skip to content

Commit

Permalink
Refine pre-filtering of attributes on content __getattr__
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Oct 1, 2019
1 parent 76bdf0b commit b3f8cc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions news/116.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Performance enhancement:
Refine pre-filtering of attributes on content ``__getattr__``.
Filter out all permissions (ending with ``_Permission``) and some portal-tools.
Also often called aquired functions are skipped.
[jensens]
21 changes: 16 additions & 5 deletions plone/dexterity/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@

# see comment in DexterityContent.__getattr__ method
ATTRIBUTE_NAMES_TO_IGNORE = (
'_v__providedBy__',
'im_self', # python 2 only, on python 3 it was renamed to __self__
'_dav_writelocks',
'aq_inner',
'_Access_contents_information_Permission'
'getCurrentSkinName',
'getURL',
'im_self', # python 2 only, on python 3 it was renamed to __self__
'plone_utils',
'portal_membership',
'portal_placeful_workflow',
'portal_properties',
'translation_service',
)


Expand Down Expand Up @@ -340,8 +346,13 @@ def __getattr__(self, name):
# defined).
# also handle special dynamic providedBy cache here.
# Ignore also some other well known names like
# Acquisition and AccessControl related ones.
if name.startswith('__') or name in ATTRIBUTE_NAMES_TO_IGNORE:
# Permission, Acquisition and AccessControl related ones.
if (
name.startswith('__')
or name.startswith('_v')
or name.endswith('_Permission')
or name in ATTRIBUTE_NAMES_TO_IGNORE
):
raise AttributeError(name)

# attribute was not found; try to look it up in the schema and return
Expand Down

0 comments on commit b3f8cc6

Please sign in to comment.