From b5d42077fa8bb3bc9c6745a9357ad47ce977e690 Mon Sep 17 00:00:00 2001 From: Hugo Branquinho Date: Mon, 16 Mar 2015 11:55:07 +0000 Subject: [PATCH 1/2] Error cloning SequenceSchema --- colander/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/colander/__init__.py b/colander/__init__.py index 1de747d..13d8d47 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -2042,9 +2042,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): From fabac87ea2dac7a3766f68fd17b60fd801501836 Mon Sep 17 00:00:00 2001 From: Hugo Branquinho Date: Thu, 21 Jan 2016 17:09:46 +0000 Subject: [PATCH 2/2] Add test case for SequenceSchema cloning error --- CONTRIBUTORS.txt | 1 + colander/tests/test_colander.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 81031f0..ad0c8a6 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -125,3 +125,4 @@ Contributors - Nando Florestan, 2014/11/27 - Amos Latteier, 2014/11/30 - Jimmy Thrasibule, 2014/12/11 +- Hugo Branquinho, 2015/01/21 diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index 8c342c8..b7cced5 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -3319,6 +3319,13 @@ class TestSequenceSchema(unittest.TestCase): e.msg, 'Sequence schemas must have exactly one child node') + 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