Prevent reparenting a block with itself (#36075)

* Prevent reparenting a block with itself

* Move __eq__ to Block, to avoid some unexpected problems

(cherry picked from commit 76ff3e9efc)
pull/36133/head
Matt Martz 7 years ago
parent 707fd61a78
commit 14dcf10882

@ -65,6 +65,10 @@ class Block(Base, Become, Conditional, Taggable):
def __repr__(self): def __repr__(self):
return "BLOCK(uuid=%s)(id=%s)(parent=%s)" % (self._uuid, id(self), self._parent) return "BLOCK(uuid=%s)(id=%s)(parent=%s)" % (self._uuid, id(self), self._parent)
def __eq__(self, other):
'''object comparison based on _uuid'''
return self._uuid == other._uuid
def get_vars(self): def get_vars(self):
''' '''
Blocks do not store variables directly, however they may be a member Blocks do not store variables directly, however they may be a member
@ -174,8 +178,16 @@ class Block(Base, Become, Conditional, Taggable):
# block their parent # block their parent
cur_obj = new_task cur_obj = new_task
while cur_obj._parent: while cur_obj._parent:
if cur_obj._parent:
prev_obj = cur_obj
cur_obj = cur_obj._parent cur_obj = cur_obj._parent
cur_obj._parent = new_block
# Ensure that we don't make the new_block the parent of itself
if cur_obj != new_block:
cur_obj._parent = new_block
else:
# prev_obj._parent is cur_obj, to allow for mutability we need to use prev_obj
prev_obj._parent = new_block
else: else:
new_task._parent = new_block new_task._parent = new_block
new_task_list.append(new_task) new_task_list.append(new_task)

Loading…
Cancel
Save