Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred validators and missing #197

Open
mazvv opened this issue Nov 15, 2014 · 1 comment
Open

Deferred validators and missing #197

mazvv opened this issue Nov 15, 2014 · 1 comment

Comments

@mazvv
Copy link

mazvv commented Nov 15, 2014

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.

@Eger37
Copy link

Eger37 commented Jan 18, 2023

May be you need to bind your schema? https://docs.pylonsproject.org/projects/colander/en/latest/binding.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants