Fixing issues with getattr caused by 5a3493b

pull/16441/head
James Cammarata 9 years ago
parent 25866e7219
commit 04fca42b62

@ -110,32 +110,16 @@ class Base:
def _generic_g(prop_name, self):
method = "_get_attr_%s" % prop_name
if hasattr(self, method):
return getattr(self, method)()
# value_found is here because we think that value needs to be changed
# in the future. self._attributes[prop_name] will return None
# sometimes, apparently if it's not explicitly set in the playbook.
# This would seem to make None a sentinel value. However, the user
# could set the attribute to None explicitly (via !!nil) which will
# not be recognized because it's being used as a sentinel. And
# sometimes _attributes[prop_name] throws a KeyError so None doesn't
# always mean that prop_name was not set. To work around these
# issues, value_found is here so that if value's behaviour is changed
# in the future, things can still be made to work.
value = getattr(self, method)()
else:
try:
value = self._attributes[prop_name]
value_found = True
except KeyError:
value = None
value_found = False
if not value_found and hasattr(self, '_get_parent_attribute'):
if value is None and hasattr(self, '_get_parent_attribute'):
value = self._get_parent_attribute(prop_name)
value_found = True
except KeyError:
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, prop_name))
if value_found:
return value
raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, prop_name))
@staticmethod
def _generic_s(prop_name, self, value):

@ -296,13 +296,13 @@ class Block(Base, Become, Conditional, Taggable):
value = self._attributes[attr]
if self._parent_block and (value is None or extend):
parent_value = getattr(self._parent_block, attr)
parent_value = getattr(self._parent_block, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
if self._task_include and (value is None or extend):
parent_value = getattr(self._task_include, attr)
parent_value = getattr(self._task_include, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:

@ -415,13 +415,13 @@ class Task(Base, Conditional, Taggable, Become):
value = self._attributes[attr]
if self._block and (value is None or extend):
parent_value = getattr(self._block, attr)
parent_value = getattr(self._block, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
value = parent_value
if self._task_include and (value is None or extend):
parent_value = getattr(self._task_include, attr)
parent_value = getattr(self._task_include, attr, None)
if extend:
value = self._extend_value(value, parent_value)
else:
@ -447,3 +447,5 @@ class Task(Base, Conditional, Taggable, Become):
'''
return self._get_parent_attribute('any_errors_fatal')
def _get_attr_loop(self):
return self._attributes['loop']

Loading…
Cancel
Save