Hello, thank you for your excellent work on creati...
# ask-community
o
Hello, thank you for your excellent work on creating and maintaining this awesome workflow tool. I have a question about
update_deployment_schedule
in
client/orchestration.py
. I am trying to change the schedule of a deployment from an external service (a client service I am creating). I am trying to update the cron using this function, but the behavior is different from what I expected, so I would like to confirm. In this function, lines 1953 to 1956 are written as follows: https://github.com/PrefectHQ/prefect/blob/1d1499a900fb4a68029a0c206b43140b0703a1b6/src/prefect/client/orchestration.py#L1953-L1956
Copy code
if active is not None:
    kwargs["active"] = active
elif schedule is not None:
    kwargs["schedule"] = schedule
I thought this code would be correct:
Copy code
if active is not None:
    kwargs["active"] = active

if schedule is not None:
    kwargs["schedule"] = schedule
With this, if both
active
and
schedule
are specified as arguments, I think the
schedule
will not be reflected. Is this the expected behavior? If this is the expected behavior, I will modify my client code to accommodate it. However, if it is not, I will raise an issue( and create the pr), so please let me know. Here is a sample code. If I do not give
active
as an argument, I can update it, but if I give
active
as an argument, the passing of
schedule
is skipped at L1953~L1956, so the cron is not updated.
Copy code
import asyncio
from prefect.client.orchestration import PrefectClient
from prefect.client.schemas.schedules import construct_schedule

async def updateDeploymentSchedule():
    client = PrefectClient(api="<http://127.0.0.1:4200/api|http://127.0.0.1:4200/api>")
    target_deployment = await client.read_deployment_by_name("foo/bar")
    schedule_id = target_deployment.schedules[0].id
    cron =construct_schedule(cron="0 5 * * *",timezone="Asia/Tokyo") # this code is working but if set `active`, cron was not updated.
    _ = await client.update_deployment_schedule(deployment_id=target_deployment.id, schedule_id=schedule_id, schedule=cron)

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(updateDeploymentSchedule())
Thank you!