colander
colander copied to clipboard
Deferred validators and missing
Hi There is a problem with deferred validators and missing. For example schema
class CrosspaymentSchema(ResourceSchema):
date = colander.SchemaNode(
Date(),
)
account_from_id = colander.SchemaNode(
colander.Integer(),
missing=None,
validator=account_from_validator
)
subaccount_from_id = colander.SchemaNode(
colander.Integer(),
missing=None,
)
and validator
class AccountFromValidator(object):
def __init__(self, request):
self.request = request
def __call__(self, node, value):
request = self.request
subaccount_from_id = cast_int(request.params.get('subaccount_from_id'))
if not value and not subaccount_from_id:
raise colander.Invalid(
node,
_(u'Set at least one account or subaccount from any section'),
)
if value and subaccount_from_id:
raise colander.Invalid(
node,
_(u'Set only account or subaccount or clear both')
)
@colander.deferred
def account_from_validator(node, kw):
request = kw.get('request')
return colander.All(AccountFromValidator(request))
I expect to get 'Set at least one account or subaccount from any section' error if both account_from_id and subaccount_from_id is empty. But I have not validation errors.
May be you need to bind your schema? https://docs.pylonsproject.org/projects/colander/en/latest/binding.html