dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

[BUG] decorator @validates_schema not working when schema loads

Open hel-o opened this issue 2 years ago • 0 comments

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 avatar Feb 22 '24 02:02 hel-o