https://prefect.io logo
r

Ryan Morshead

07/17/2023, 10:57 PM
When I call
Deployment.apply
with changes attributes they are not reflected on the Prefect server. Given that
Deployment.apply
does not have an
override
parameter. How can I update an existing deployment. [SOLVED]
e

Emil Christensen

07/18/2023, 4:15 PM
@Ryan Morshead could you provide some of the code you are using? What attributes are you changing? Calling
.apply
on a deployment should replace it (or create it if it doesn’t exist).
r

Ryan Morshead

07/18/2023, 4:16 PM
I am changing the
infra_overrides
I’m currently using the code below to create/update, but it’s definitely a hack:
Copy code
async def apply_deployment(deployment: Deployment) -> UUID:
    """Apply a deployment or update it if it already exists"""
    client = get_client()
    try:
        existing_deployment = await get_client().read_deployment_by_name(f"{deployment.flow_name}/{deployment.name}")
    except ObjectNotFound:
        return await deployment.apply()
    else:
        # copy attributes from my new deployment to the current deployment
        for name in deployment.__fields__:
            if hasattr(existing_deployment, name):
                setattr(existing_deployment, name, getattr(deployment, name))
        await client.update_deployment(existing_deployment)
        return existing_deployment.id
@Emil Christensen, not sure if this has already been patched, I’m currently using v2.10.8
e

Emil Christensen

07/18/2023, 4:27 PM
And in this case,
Deployment
is what? Is it an instance of
prefect.deployments.Deployment
?
r

Ryan Morshead

07/18/2023, 4:29 PM
Correct.
update_deployment
seems to expect a
DeploymentReponse
or an ORM
Deployment
e

Emil Christensen

07/18/2023, 4:31 PM
And what is returned from
return await deployment.apply()
? Does it give you back the UUID of the deployment?
r

Ryan Morshead

07/18/2023, 4:31 PM
Correct
Looking through the code of
apply
unless there’s something special that the backend does with a
CreateDeployment
request, it doesn’t seem like
apply
should actually update an existing deployment.
@Emil Christensen, I feel like I’ve identified the problem.
Deployment.apply
is looking for
_block_document_id
here. However,
Deployment.load
never seems to set it.
This might error though since
_block_document_id
is not declared as a
Field
of
Deployment
(which further suggests this is likely the isssue).
e

Emil Christensen

07/18/2023, 4:59 PM
Hmm… I’ve only ever used
Deployment.build_from_flow
to construct `Deployment`s. Is there a reason you’re constructing it directly?
r

Ryan Morshead

07/18/2023, 5:01 PM
I’m using
Deployment.build_from_flow
and
load_existing=True
Sorry. I’m completely misunderstanding the code there…
This may not be an issue after all… I just tried again today and it seem to be updating. I must have been doing something wrong.
1