Alex Papanicolaou
10/11/2024, 5:30 AMself
is listed as a parameter and I get this error: Error creating flow run: Validation failed. Failure reason: 'self' is a required property"
What should be done?Marvin
10/11/2024, 5:30 AMself
parameter. Prefect currently requires explicit handling of self
since it is considered a parameter in the flow's signature.
The good news is that there's been a pull request to add support for decorating instance/class/static methods as @flows
or @tasks
. The issue arises because the implicit self
parameter is not handled automatically by Prefect. This causes errors such as:
"Error binding parameters for function 'instance_method': missing a required argument: 'self'. Function 'instance_method' has signature 'self' but received args: () and kwargs: []."
The solution being implemented involves:
1. Adding a __get__
method that helps bind the instance method correctly when accessed on its parent instance.
2. Modifying Prefect's get_call_parameters
function to look for a __prefect_self__
attribute and handle it as if it was a normal parameter.
This should eventually allow you to define flows and tasks using class methods without manually handling self
as an argument.
For now, as a workaround, you might consider making these methods into standalone functions or passing your class instance as an explicit parameter until these changes are fully integrated and released in a future version.
You can follow the progress and updates on this topic through the pull request Add support for instance/class/static methods.
If you're having trouble determining the Prefect version you are using, please check with your local environment or project setup, as the solution or workaround may vary based on your version.Alex Papanicolaou
10/11/2024, 5:35 AMAlex Papanicolaou
10/11/2024, 5:53 AMNate
10/11/2024, 2:28 PM