Robert Szomolanyi
05/12/2026, 7:57 AMMarvin
05/12/2026, 7:57 AMMarvin
05/12/2026, 7:58 AMrun_deployment() returns a flow run object, and you get the flow’s returned data from its final state.
Important: if you want to read the returned value reliably, enable result persistence on the flow.
Example:
python
from prefect import flow
from prefect.deployments import run_deployment
@flow(persist_result=True)
def my_flow(x: int):
return {"input": x, "output": x * 2}
if __name__ == "__main__":
flow_run = run_deployment(
name="my-flow/my-deployment",
parameters={"x": 21},
)
# run_deployment returns a FlowRun, not the result directly
result = flow_run.state.result()
print(result) # {"input": 21, "output": 42}
If you want to be a bit safer and inspect the state first:
python
from prefect import flow
from prefect.deployments import run_deployment
@flow(persist_result=True)
def my_flow(x: int):
return x * 2
flow_run = run_deployment(
name="my-flow/my-deployment",
parameters={"x": 10},
)
if flow_run.state.is_completed():
result = flow_run.state.result()
print(f"Result: {result}")
elif flow_run.state.is_failed():
error = flow_run.state.result(raise_on_failure=False)
print(f"Flow failed: {error}")
else:
print(f"Flow is in state: {flow_run.state.type}")
Notes:
- run_deployment(...) → returns FlowRun
- actual flow return value → flow_run.state.result()
- use @flow(persist_result=True) so the result is stored and can be retrieved
If you want, I can also show:
- an async example
- how to do this when the deployment is triggered and checked later
- how to configure remote result storage for Docker/Kubernetes workersRobert Szomolanyi
05/12/2026, 9:25 AMMarvin
05/12/2026, 9:25 AMMarvin
05/12/2026, 9:26 AMflow_run.state.result() does not always read from local storage in principle, but in your current setup it is trying to read from a local filesystem result store, and that local path only exists in the worker environment.
Because your worker runs in WSL and your client runs in Windows:
- worker writes result to something like /home/adam/.prefect/storage/... inside WSL
- Windows client tries to resolve it as C:\home\adam\.prefect\storage\...
- that path does not exist on Windows
- so flow_run.state.result() fails
So yes: local result storage is not safe across different environments/hosts.
What this means generally
- If worker and caller are in the same environment, local storage can work
- If worker is on another host, container, VM, Kubernetes pod, WSL, etc., local storage usually will not work
- For cross-host result retrieval, use shared/remote result storage
Recommended fix
Use a result storage backend both the worker and the client can access, for example:
- S3
- GCS
- Azure Blob
- SMB / network share
Then flow_run.state.result() can fetch the result from that shared backend.
Example with explicit result storage on the flow:
python
from prefect import flow
@flow(
persist_result=True,
result_storage="s3-bucket/my-shared-results"
)
def my_flow(x: int):
return {"value": x * 2}
Then from your Windows client:
python
from prefect.deployments import run_deployment
flow_run = run_deployment(
name="my-flow/my-deployment",
parameters={"x": 21},
)
result = flow_run.state.result()
print(result)
That works as long as both environments can access the same S3 bucket/block configuration.
Why local storage fails on another host
Local filesystem storage stores results on the machine that executed the flow.
If the reader is on a different machine, that path is meaningless unless it points to a shared mount visible at the same location.
So this is not just a Windows/WSL issue — the same problem happens with:
- local laptop client + remote VM worker
- local client + Docker worker
- local client + Kubernetes worker
Good rule of thumb
- local filesystem result storage → only for single-machine setups
- remote/shared storage → for any real deployment setup
If you want, I can show you a full working example for:
- S3 result storage
- shared network folder / SMB
- or a minimal local workaround for Windows + WSL on the same machine