framework
framework copied to clipboard
Possible issue with `from_descriptor` for custom checks
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)