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

[BUG] decorator @validates_schema not working when schema loads #520

Open
hel-o opened this issue Feb 22, 2024 · 0 comments
Open

[BUG] decorator @validates_schema not working when schema loads #520

hel-o opened this issue Feb 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@hel-o
Copy link

hel-o commented Feb 22, 2024

Description

The @validates_schema decorator does not work when the Schema is loaded.

Code snippet that reproduces the issue

@dataclass_json
@dataclass
class Person:
    name: str = field(
        metadata=config(
            mm_field=fields.String(required=True, validate=validate.Length(min=1, max=15))
        )
    )

    surname: str = field(
        metadata=config(
            mm_field=fields.String(
                validate=validate.Length(min=3, max=15)
            )
        )
    )

    @validates_schema()
    def validate_user_auth(self, data: dict, **kwargs) -> None:
        print('not working...')

    def save(self):
        print('db value:', self.name)


if __name__ == '__main__':
    try:
        value = Person.schema().loads('{"name": "1", "surname": "abd"}')
    except ValidationError as e:
        print(e.messages)
    else:
        print(value.name, ":", value.surname)

Describe the results you expected

the function: validate_user_auth should be called.

Python version you are using

3.12

Environment description

marshmallow==3.20.2
dataclasses-json==0.6.4

@hel-o hel-o added the bug Something isn't working label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant