https://prefect.io logo
Title
r

Riccardo Tesselli

07/20/2022, 8:08 AM
In Prefect 2.0, I’m trying to create a Deployment which takes arguments from a configuration stored in Prefect Cloud as a custom block. Here is the sample code:
config = CustomConfig.load('my_block')

Deployment(
    name="My deployment",
    flow=my_flow,
    parameters={
        "password": config.password
    }
)
when I run this command from CLI
prefect deployment create my_deployment.py
I get this error
AttributeError: 'coroutine' object has no attribute 'password'

Failed to load deployments from 'my_deployment.py'
sys:1: RuntimeWarning: coroutine 'Block.load' was never awaited
How can I do that?
a

Anna Geller

07/20/2022, 10:33 AM
Try out the Secret block instead that just got released
r

Riccardo Tesselli

07/20/2022, 11:24 AM
thanks @Anna Geller, but I think my situation is different from the example you provided. I know I can save and load blocks within flows, but at the moment I want to create a deployment as described in https://orion-docs.prefect.io/concepts/deployments/#creating-deployments by using the CLI. I’ve supposed that load would also work outside a flow but it looks like it doesn’t. Now I’m trying to create the deployment directly in Python with
Deployment.create()
, but now I’m facing with this error:
here is the code
if __name__ == '__main__':

    config = CustomConfig.load('my_setup')

    deployment = Deployment(
        name="MyDeployment",
        flow=my_flow,
        parameters={
            "password": config.password,
            "slack_webhook": config.slack_webhook        }
    )
    deployment.create()
and I get this
TypeError: Object of type 'AsyncWebhookClient' is not JSON serializable
so it looks like Pydantic is failing in serializing the Slack Webhook Block
so at the end I’ve fixed by doing this
if __name__ == '__main__':

    config = CustomConfig.load('my_setup')

    deployment = Deployment(
        name="MyDeployment",
        flow=my_flow,
        parameters={
            "password": config.password,
            "slack_webhook": config.slack_webhook.url        }
    )
    deployment.create()
nevertheless, it could be handy to be able to quickly inject a block stored in the cloud into a deployment
a

Anna Geller

07/20/2022, 12:50 PM
we'll have more Deployment recipes after GA release, it should get easier in the next weeks