You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
I also ran into this issue, and our schema is indeed bound.
The only way I was able to resolve it was by overriding the missing values in deserialize - this seems like a hack, but I don't see a better way as of now.
Ideally it would be great to find some way to have the validators run even if missing sets None - I imagine the problem is that None implies there is no value, or nothing to validate, since None is valid according to missing
# For some `SchemaNode`
def deserialize(self, cstruct):
request = self.bindings["request"]
blah = request.json_body.get("blah")
if (
blah is None
or blah is ""
):
self.missing = required
self.missing_msg = "Custom Message"
return super().deserialize(cstruct)
Hi
There is a problem with deferred validators and missing. For example schema
and validator
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.
The text was updated successfully, but these errors were encountered: