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

@ -49,7 +49,7 @@ class Conditional:
to be run conditionally when a condition is met or skipped.
'''
_when = FieldAttribute(isa='list', default=[])
_when = FieldAttribute(isa='list', default=[], extend=True, prepend=True)
def __init__(self, loader=None):
# when used directly, this class needs a loader, but we want to
@ -66,17 +66,6 @@ class Conditional:
if not isinstance(value, list):
setattr(self, name, [value])
def _get_attr_when(self):
'''
Override for the 'tags' getattr fetcher, used from Base.
'''
when = self._attributes['when']
if when is None:
when = []
if hasattr(self, '_get_parent_attribute'):
when = self._get_parent_attribute('when', extend=True, prepend=True)
return when
def extract_defined_undefined(self, conditional):
results = []