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

self methods in validation attributes #123

Open
pozitronik opened this issue Oct 9, 2024 · 0 comments
Open

self methods in validation attributes #123

pozitronik opened this issue Oct 9, 2024 · 0 comments
Assignees
Labels
dev 🧑‍💻Developer issues (todos, experiments, styling, etc)

Comments

@pozitronik
Copy link
Owner

There's an issue when using any parametrized self method in any validation rule as lambda function:

    def rules(self) -> Rules:
        return [
            {
                'parameter': {'log', 'logfile'},
                'attribute': 'logfile',
                'default': None,
                'valid': lambda attribute, value: self.init_logger(self, value),  # <===
                'help': 'Path to the log file'
            }
        ]

ValueValidator calls any validation method as static, therefore it is required to pass self as first parameter to preserve right context, which is breaking code validation.
The possible solution is to check method context in ValueValidator, and add self explicitly.

@pozitronik pozitronik added the dev 🧑‍💻Developer issues (todos, experiments, styling, etc) label Oct 9, 2024
@pozitronik pozitronik self-assigned this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev 🧑‍💻Developer issues (todos, experiments, styling, etc)
Projects
None yet
Development

No branches or pull requests

1 participant