Skip self._parent on dynamic, defer to grandparent for attr lookup (#38827)

* Skip self._parent on dynamic, defer to grandparent for attr lookup

* Revert _inheritable

* Add tests for include inheritance from static blocks

Fixes #38037 #36194
This commit is contained in:
Matt Martz 2018-04-16 16:46:47 -05:00 committed by GitHub
commit 354aa8d602
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 63 additions and 16 deletions

View file

@ -423,13 +423,20 @@ class Task(Base, Conditional, Taggable, Become):
prepend = self._valid_attrs[attr].prepend
try:
value = self._attributes[attr]
if self._parent and (value is None or extend):
if getattr(self._parent, 'statically_loaded', True):
# If parent is static, we can grab attrs from the parent
# otherwise, defer to the grandparent
if getattr(self._parent, 'statically_loaded', True):
_parent = self._parent
else:
_parent = self._parent._parent
if _parent and (value is None or extend):
if getattr(_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 getattr(self._parent, '_inheritable', True) and hasattr(self._parent, '_get_parent_attribute'):
parent_value = self._parent._get_parent_attribute(attr)
if attr != 'vars' and hasattr(_parent, '_get_parent_attribute'):
parent_value = _parent._get_parent_attribute(attr)
else:
parent_value = self._parent._attributes.get(attr, None)
parent_value = _parent._attributes.get(attr, None)
if extend:
value = self._extend_value(value, parent_value, prepend)