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

Possible issue with from_descriptor for custom checks #1612

Open
pierrecamilleri opened this issue Nov 29, 2023 · 0 comments
Open

Possible issue with from_descriptor for custom checks #1612

pierrecamilleri opened this issue Nov 29, 2023 · 0 comments

Comments

@pierrecamilleri
Copy link

Not sure if this is an issue or intended behavior, so if you think there is a better place, do not hesitate to tell me where I can move the conversation.

We have a use case where we define custom checks (that inherit from frictionless.Check), with custom types. In the process of migrating from frictionless v4 to v5, we noticed that these custom types would throw errors when using CustomCheck.from_descriptor : [check-error] Check is not valid: check type "custom-check" is not supported

Looking into the codebase, we noticed that this issue was raised by system.select_check_class. In this function, from what I understand, there are two main ways for a class to be selected :

  • with a plugin overwriting select_check_class (I am not very familiar with plugins, so I may have misunderstood)
  • from a closed list of allowed classes/types (frictionless.checks)

I wonder why the allowed types need to be narrowed down to a closed list this way. Is there a way to "register" an additional allowed type, or what is the best/suggested way to implement custom checks with custom types ? Is a plugin the way to go ?

The workaround we found so far consists in overwriting the metadata_select_class method of Check, but this feels a bit clunky.

Sample custom check code

This fails with a CheckError. Uncomment the commented block and it behaves as expected.

from typing import Optional

from frictionless import Check, errors, validate


class CustomCheck(Check):
    type: str = "custom-check"

    def validate_start(self):
        yield errors.Error(note="custom check error")

    # Uncomment and it works as expected
    # @classmethod
    # def metadata_select_class(cls, _: Optional[str]):
    #     return cls


if __name__ == "__main__":
    report = validate(
        source=[["a"], [1]],
        checks=[CustomCheck.from_descriptor({"type": "custom-check"})],
    )
    print(report)
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

1 participant