Merge pull request #167 from claytron/issue_139_default_drop

fix serialization of default with drop
This commit is contained in:
Joe Dallago
2014-02-09 14:36:23 -06:00
3 changed files with 25 additions and 10 deletions

View File

@@ -9,6 +9,9 @@ Bug Fixes
- Set the max length TLD to 22 in ``Email`` validator based on the
current list of valid TLDs.
See https://github.com/Pylons/colander/issues/159
- Fix an issue where ``drop`` was not recognized as a default and was
returning the ``drop`` instance instead of omitting the value.
https://github.com/Pylons/colander/issues/139
Features
~~~~~~~~

View File

@@ -572,7 +572,8 @@ class Mapping(SchemaType):
for num, subnode in enumerate(node.children):
name = subnode.name
subval = value.pop(name, null)
if subval is not drop:
if subval is drop or (subval is null and subnode.default is drop):
continue
try:
sub_result = callback(subnode, subval)
except Invalid as e:
@@ -580,7 +581,8 @@ class Mapping(SchemaType):
error = Invalid(node)
error.add(e, num)
else:
if sub_result is not drop:
if sub_result is drop:
continue
result[name] = sub_result
if self.unknown == 'raise':

View File

@@ -3153,6 +3153,16 @@ class TestSchema(unittest.TestCase):
result = node.deserialize(expected)
self.assertEqual(result, expected)
def test_serialize_drop_default(self):
import colander
class MySchema(colander.Schema):
a = colander.SchemaNode(colander.String())
b = colander.SchemaNode(colander.String(), default=colander.drop)
node = MySchema()
expected = {'a': 'foo'}
result = node.serialize(expected)
self.assertEqual(result, expected)
class TestSequenceSchema(unittest.TestCase):
def test_succeed(self):
import colander