Permalink
Browse files

Merge pull request #302 from ralt/fix-mapping-refs

Copy the mapping values when serializing.
  • Loading branch information...
tseaver committed Mar 8, 2018
2 parents 995d368 + 04c969f commit 1ce3085c1a2fd671374995202833a457d095c99c
Showing with 17 additions and 1 deletion.
  1. +2 −1 colander/__init__.py
  2. +15 −0 colander/tests/test_colander.py
View
@@ -1,5 +1,6 @@
# coding=utf-8
+import copy
import datetime
import decimal
import functools
@@ -698,7 +699,7 @@ def _impl(self, node, value, callback):
mapping={'val': value}))
elif self.unknown == 'preserve':
- result.update(value)
+ result.update(copy.deepcopy(value))
if error is not None:
raise error
@@ -2856,6 +2856,21 @@ def compare_children(schema, cloned):
schema.children = list(reversed(schema.children))
compare_children(schema, schema.clone())
+ def test_clone_mapping_references(self):
+ import colander
+ class Schema(colander.MappingSchema):
+ n1 = colander.SchemaNode(colander.Mapping(unknown='preserve'))
+ foo = {
+ "n1": {
+ "bar": {
+ "baz": "qux",
+ },
+ },
+ }
+ bar = Schema().serialize(foo)
+ bar["n1"]["bar"]["baz"] = "foobar"
+ self.assertEqual(foo["n1"]["bar"]["baz"], "qux")
+
def test_bind(self):
from colander import deferred
inner_typ = DummyType()

0 comments on commit 1ce3085

Please sign in to comment.