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

@validates decorated function is invoked when the field is loaded with the default value #2048

Open
dharani7998 opened this issue Sep 12, 2022 · 1 comment

Comments

@dharani7998
Copy link

dharani7998 commented Sep 12, 2022

Here id field has a load_default value, it doesn't invoke the fn_validator when the value is not present in the dict but it invokes the decorator function

def fn_validator(value: int):
    print(f'In fn_validator: {value}')

class Test(Schema):
    id = fields.Int(load_default=None, validate=fn_validator)

    @validates('id')
    def dec_validator(self, value, **kwargs):
        print(f'In dec_validator: {value}')


sch = Test()
sch.load({'id': 123})
print('=========================')
sch.load({})
@deckar01
Copy link
Member

The schema would need to either keep track of which values are defaulted, or pass the extra validator methods to the field during initialization. I would lean toward the latter, but honestly I am not very motivated to add code to normalize what seems to be an inert side effect.

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