<@ULVA73B9P> with prefect 2, it seems like I can s...
# ask-marvin
m
@Marvin with prefect 2, it seems like I can succesfully do
build_from_flow(flow=MyClass.my_first_flow)
but when running the follow it will attempt to run my_first_flow without going through the class
m
It seems you're encountering a quirk with Prefect 2.x when trying to run a flow with
build_from_flow
from a class method. While I couldn't retrieve the exact documentation details right now, an issue was found related to the creation of deployments through Python. It seems there is some functionality not automatically invoked, like creating certain files or configurations. However, from your description, it sounds like the method invocation doesn't go through the expected class hierarchy. In Python, invoking a class method directly can sometimes bypass the class context if not handled correctly. Here's a general suggestion you might try: Ensure that
MyClass.my_first_flow
is a static method or a class method if you’re trying to avoid direct instantiation. You might need to ensure that the flow is properly instantiated and called within the class. For example:
Copy code
python
from prefect import Flow
from prefect.deployments import Deployment

class MyClass:
    @staticmethod
    def my_first_flow():
        with Flow("example") as flow:
            # Your tasks and logic here
            pass
        return flow

flow_instance = MyClass.my_first_flow()
deployment = Deployment.build_from_flow(flow=flow_instance)
deployment.apply()
Given the peculiarities of Prefect, make sure that the flow is returned correctly and that any context decorators in use are properly applied. You may also need to investigate more specific issues in GitHub or Prefect forums if there’s a version-specific bug or behavior. If this doesn't help, I recommend exploring Prefect's GitHub issues further or asking on their forum where more version-specific solutions might exist. If only this search tool of mine wasn’t feeling particularly stubborn today!
n
hi @Mehdi - i am fixing the issue with docs retrieval right now but im not sure i understand your question
when running the follow it will attempt to run my_first_flow without going through the class
what do you mean "going through the class"?
m
running the flow**
Let me show you the error I get
It will raise the following error:
Copy code
raise MissingFlowError(
prefect.exceptions.MissingFlowError: Flow function with name 'my_first_flow' not found in 'path/to/class/myclass_file.py'.
Structure consists, in having two files: • myclass_file.py : containing the class with a static/class method with flow decorator • main.py : that will import the class and do the following
build_from_flow(flow=<http://MyClass.my|MyClass.my>_first_flow)
I only tested running the flow from the UI, and not with the .run()/.apply()
fyi @Nate