PrefectHQ / prefect

Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
https://prefect.io
Apache License 2.0
15.32k stars 1.5k forks source link

how to get run_deployment result #14397

Closed jsshizhan closed 2 days ago

jsshizhan commented 3 days ago

First check

Bug summary

parent flow run machine A,with a subflow run_deployment in machine B,how to get suflow return value in parent flow? flowrun.state has no return value

Reproduction

@flow(flow_run_name="subflow",persist_result=True)
async def subflow():
    future = hello_dask.submit()
    result = future.result()
    return Completed(message="this is a message111",data=result)

@flow(log_prints=True,flow_run_name="root_flow")
async def buy():
    flowRun = await run_deployment(
        name="subflow/deployment_subflow",
    )
    print(flowRun.state.data)

Error

No response

Versions (prefect version output)

prefect version
Version:             3.0.0rc9
API version:         0.8.4
Python version:      3.12.3
Git commit:          b75631a7
Built:               Mon, Jun 24, 2024 5:50 PM
OS/Arch:             darwin/x86_64
Profile:             default
Server type:         server
Pydantic version:    2.7.3

Additional context

No response

zhen0 commented 2 days ago

Hi @jsshizhan - thanks for the issue and the question! If I understand your question correctly you want to know how to get access to the result when running run_deployment? Your example is close but you'll probably find it easier to return your result directly instead of trying to add it to the state. You can see more examples and an explanation of returning values in the docs here: https://docs-3.prefect.io/3.0rc/develop/manage-states#returned-values

A side note that this will return the result location rather than the result itself. You might also want to look into using a variable - https://docs-3.prefect.io/3.0rc/develop/variables#manage-variables

Looking into your question did make me realize that we could do with more documentation on run_deployment - I've added an issue for that here

As a side note, I had to do some reworking to get your MRE to run because you referenced tasks that weren't actually available. Here's a good explanation of what we are looking for when running an MRE - https://stackoverflow.com/help/minimal-reproducible-example

zhen0 commented 2 days ago

I'm going to close this issue as I don't see this as a bug. Please do open a new issue or re-open this one if you feel I've not actually addressed your question.