diff --git a/CHANGES.rst b/CHANGES.rst index 0357a8d..4205219 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ unreleased - Allow deferred schema nodes. See https://github.com/Pylons/colander/pull/280 +- Fix an issue when using a node multiple times in a schema by cloning it. + See https://github.com/Pylons/colander/issues/279 + 1.3.1 (2016-05-23) ================== diff --git a/colander/__init__.py b/colander/__init__.py index 08f8446..c5de77c 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -2242,7 +2242,7 @@ class _SchemaMeta(type): value.title = name.replace('_', ' ').title() nodes.append((value._order, value)) - nodes.sort() + nodes.sort(key=lambda n: n[0]) cls.__class_schema_nodes__ = [ n[1] for n in nodes ] # Combine all attrs from this class and its _SchemaNode superclasses. diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index 8cda68c..28ce8cf 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -3403,6 +3403,17 @@ class TestSchema(unittest.TestCase): self.assertEqual(schema.schema_type, colander.Mapping) self.assertEqual(schema.children[0], node) + def test_schema_with_cloned_nodes(self): + import colander + test_node = colander.SchemaNode(colander.String()) + class TestSchema(colander.Schema): + a = test_node.clone() + b = test_node.clone() + node = TestSchema() + expected = {'a': 'foo', 'b': 'bar'} + result = node.serialize(expected) + self.assertEqual(result, expected) + class TestSequenceSchema(unittest.TestCase): def test_succeed(self): import colander