Hi prefect devs, Found a new GOTCHA on prefect dep...
# ask-community
d
Hi prefect devs, Found a new GOTCHA on prefect deployment.
Deployment.build_from_flow
does not redeploy a new deployment if a deployment with the same name exists - the new deployment is updated over the previous deployment.
What does this mean? Below is an example code that creates a deployment of a flow with preset parameter. And then attempts to update the deployment without the parameters. The updated deployment will still retain the parameters from the previous deployment.
Copy code
import asyncio

from prefect import flow
from prefect.client.orchestration import get_client
from prefect.deployments import Deployment

DEPLOYMENT_NAME = "test_deployment"


async def get_deployment():
    async with get_client() as client:
        return await client.read_deployment_by_name(
            f"{DEPLOYMENT_NAME}/{DEPLOYMENT_NAME}"
        )


@flow(name=DEPLOYMENT_NAME)
def f(a: int = 1):
    print(a)


if __name__ == "__main__":
    deployment_parameters = dict(
        flow=f,
        name=DEPLOYMENT_NAME,
        is_schedule_active=False,
        apply=True,
    )

    Deployment.build_from_flow(
        **deployment_parameters,
        parameters={"a": "b"},
    )
    deployment = asyncio.run(get_deployment())
    print(deployment.parameters)  # Returns {"a":"b"}

    Deployment.build_from_flow(**deployment_parameters)
    deployment = asyncio.run(get_deployment())
    print(deployment.parameters)  # Still returns {"a":"b"}
Consequences : For example in our usecase, We used to have an infra_override to override the image being used by the pod in kubernetes and at some point we stopped using the infra_override and moved the code to kubernetes job block where we specify the image. Few bug fixes in flow code and test it locally on locally hosted server. Great! everything works. Deploy it to the server and infraoveride of old deployment are still active. Older flow from older image tag gets pulled in, new fixes are not executed, dev hours spent debugging the issue.
I havnt tested the prefect cli deployments but I assume it is the same.
Seems like this is intended.