Skip to content

Commit

Permalink
Change Field.clone() to preserve .parent
Browse files Browse the repository at this point in the history
The reasons for this (and some alternatives) are listed at
Pylons#187 (comment)
  • Loading branch information
dairiki committed Sep 16, 2015
1 parent 05e340c commit 3b619d6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions deform/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,15 @@ def clone(self):
attribute of the node is not cloned; instead the field
receives a new order attribute; it will be a number larger
than the last rendered field of this set. The parent of the cloned
node will become ``None`` unconditionally."""
node will be retained by the clone."""
cloned = self.__class__(self.schema)
cloned.__dict__.update(self.__dict__)
cloned.order = next(cloned.counter)
cloned.oid = 'deformField%s' % cloned.order
cloned._parent = None
parent = self.parent
if parent is not None:
parent = weakref.ref(parent)
cloned._parent = parent
children = []
for field in self.children:
cloned_child = field.clone()
Expand Down

0 comments on commit 3b619d6

Please sign in to comment.