https://prefect.io logo
Title
t

Tuoyi Zhao

08/24/2022, 10:17 PM
I build deployment object using: prefect.deployments.Deployment.build_from_flow(), but this object does not have apply() method? how should I deploy a flow from Python instead of CLI?
1
c

Cole Murray

08/24/2022, 10:22 PM
What version of prefect are you using?
t

Tuoyi Zhao

08/24/2022, 10:23 PM
@Cole Murray Hi Cole, I'm using the 2.2.0
c

Cole Murray

08/24/2022, 10:26 PM
Based on the error message, it looks like it is being run in an async context. You might need to call await on the object or alter your code to run in a sync context: https://github.com/PrefectHQ/prefect/blob/main/src/prefect/deployments.py#L469 https://github.com/PrefectHQ/prefect/blob/main/src/prefect/deployments.py#L426 Could you paste any other relevant code?
t

Tuoyi Zhao

08/24/2022, 10:27 PM
Hi @Cole Murray below are the simple test code i used: import prefect from prefect import flow, task from prefect.deployments import Deployment @flow() def dynamic_parameter(): return 1
a

Andrew Huang

08/24/2022, 10:28 PM
if you’re running on notebook, you need to do
deployment = await Deployment.build_from_flow()
t

Tuoyi Zhao

08/24/2022, 10:31 PM
Hi @Andrew Huang, thanks for your response, I got below error with await......
a

Andrew Huang

08/24/2022, 10:32 PM
I think you’re supposed to run deployments in py scripts, not notebook
t

Tuoyi Zhao

08/24/2022, 10:39 PM
@Andrew Huang yeah, it works in py script..... anyway, do we no longer have equivalent of flow.register() in Prefect 1.0? That one works perfectly in the notebook.
a

Andrew Huang

08/24/2022, 10:41 PM
not that I know of. perhaps you can submit an issue to Github as a feature request?
👍 1
t

Tuoyi Zhao

08/24/2022, 10:43 PM
@Andrew Huang Good idea....sorry i supposed you are of Prefect developer team.
a

Andrew Huang

08/24/2022, 10:45 PM
XD actually I am (but I don’t work on deployments)
😁 1