diff --git a/pecan/core.py b/pecan/core.py index 3a68102..2dc5a38 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -360,7 +360,7 @@ class Pecan(object): raise ValidationException() if json: params = dict(data=params) - return params + return params or {} def handle_request(self): ''' diff --git a/tests/test_validation.py b/tests/test_validation.py index 921ab05..815d2a5 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -78,6 +78,31 @@ class TestValidation(object): )), [('content-type', 'application/json')]) assert r.status_int == 200 assert r.body == 'Success!' + + def test_validation_with_none_type(self): + """ + formencode schemas can be configured to return NoneType in some + circumstances. We use the output of formencode's validate() to + determine wildcard arguments, so we should protect ourselves + from this scenario. + """ + class RegistrationSchema(Schema): + if_empty = None + first_name = validators.String(not_empty=True) + last_name = validators.String(not_empty=True) + + class RootController(object): + @expose(schema=RegistrationSchema()) + def index(self, **kw): + assert 'first_name' not in kw + assert 'last_name' not in kw + return 'Success!' + + # test form submissions + app = TestApp(make_app(RootController())) + r = app.post('/', dict()) + assert r.status_int == 200 + assert r.body == 'Success!' def test_simple_failure(self): class RegistrationSchema(Schema):