Don't use getattr in _get_parent_attribute to avoid recursion issues (#33595)

* Don't use getattr in _get_parent_attribute to avoid recursion issues

Fixes #23609

* Move extend/prepend to field attribute

Also removes _get_attr* methods that were basically just calling
_get_parent_attribute because it needed to set those params.

Also modifies _get_parent_attribute() to pull those values from the
FieldAttributes instead of using the ones passed into the function.

* Better fixes for _get_parent_attribute
This commit is contained in:
James Cammarata 2018-01-05 20:51:44 -06:00 committed by Brian Coca
commit ebf971f931
7 changed files with 53 additions and 54 deletions

View file

@ -414,16 +414,17 @@ class Task(Base, Conditional, Taggable, Become):
Generic logic to get the attribute or parent attribute for a task value.
'''
value = None
extend = self._valid_attrs[attr].extend
prepend = self._valid_attrs[attr].prepend
try:
value = self._attributes[attr]
if self._parent and (value is None or extend):
if attr != 'when' or getattr(self._parent, 'statically_loaded', True):
if getattr(self._parent, 'statically_loaded', True):
# vars are always inheritable, other attributes might not be for the partent but still should be for other ancestors
if attr != 'vars' and not getattr(self._parent, '_inheritable', True) and hasattr(self._parent, '_get_parent_attribute'):
parent_value = self._parent._get_parent_attribute(attr, extend=extend, prepend=prepend)
if attr != 'vars' and getattr(self._parent, '_inheritable', True) and hasattr(self._parent, '_get_parent_attribute'):
parent_value = self._parent._get_parent_attribute(attr)
else:
parent_value = getattr(self._parent, attr, None)
parent_value = self._parent._attributes.get(attr, None)
if extend:
value = self._extend_value(value, parent_value, prepend)
@ -442,12 +443,6 @@ class Task(Base, Conditional, Taggable, Become):
value = C.ANY_ERRORS_FATAL
return value
def _get_attr_environment(self):
'''
Override for the 'tags' getattr fetcher, used from Base.
'''
return self._get_parent_attribute('environment', extend=True, prepend=True)
def get_dep_chain(self):
if self._parent:
return self._parent.get_dep_chain()