diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index b9097bd..334e263 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -128,6 +128,7 @@ Contributors - Nando Florestan, 2014/11/27 - Amos Latteier, 2014/11/30 - Jimmy Thrasibule, 2014/12/11 +- Hugo Branquinho, 2015/01/21 - Daniel Dourvaris, 2015/03/04 - Dmitry Bogun, 2015/09/10 - Tinne Cahy, 2015/12/22 diff --git a/colander/__init__.py b/colander/__init__.py index a228266..949a36d 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -2116,9 +2116,12 @@ class _SchemaNode(object): """ Clone the schema node and return the clone. All subnodes are also cloned recursively. Attributes present in node dictionaries are preserved.""" - cloned = self.__class__(self.typ) - cloned.__dict__.update(self.__dict__) - cloned.children = [ node.clone() for node in self.children ] + children = [node.clone() for node in self.children] + cloned = self.__class__(self.typ, *children) + + attributes = self.__dict__.copy() + attributes.pop('children', None) + cloned.__dict__.update(attributes) return cloned def bind(self, **kw): diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index f8badc8..c58dd23 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -3423,6 +3423,13 @@ class TestSequenceSchema(unittest.TestCase): result = node.serialize([colander.null]) self.assertEqual(result, []) + def test_clone(self): + import colander + thingnode = colander.SchemaNode(colander.String()) + thingnode2 = colander.SchemaNode(colander.String()) + schema = colander.SequenceSchema(colander.Sequence(), thingnode, thingnode2) + schema.clone() + class TestTupleSchema(unittest.TestCase): def test_it(self): import colander