<@ULVA73B9P> With the Prefect Cloud API, the updat...
# ask-marvin
j
@Marvin With the Prefect Cloud API, the update deployment PATCH call accepts schedules as an attribute that can be modified. When I attempt to update the parameters of a schedule, it actually sets them to an empty object. Is this intended?
m
It seems that the behavior you're experiencing with the Prefect Cloud API's
PATCH
call for updating deployment schedules might not be well-documented or a known issue. However, the documentation does mention that when updating a deployment schedule, typically only basic information such as a cron string or interval is required. This implies that the API might not handle more complex parameter updates for schedules as expected, potentially leading to them being reset or set to empty objects. If you are encountering this issue consistently, it might be worth reaching out to Prefect support or checking if there are any updates or patches that address this behavior. You can refer to the Prefect documentation on deployments and schedules for more details: Prefect Deployment Documentation. If this is a critical issue, consider filing a bug report on the Prefect GitHub repository with details of your API call and the unexpected behavior.
👍 1
j
Hi @Nate! Definitely, here is an example:
Copy code
import json
import httpx

# Setup the Client
prefect_client = httpx.Client(
    base_url=api_url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
)

# Get the Existing Flow ID
flow_name = "Test Flow 480a35"
deployment_name = "Test Deployment 480a35"
deployment_resp = prefect_client.get(url=f"deployments/name/{flow_name}/{deployment_name}")

# Update the Flow's schedules (only one in this case) via PATCH
patch_resp = prefect_client.patch(
    url=f"deployments/{deployment_resp.json()['id']}",
    json={
        "schedules": [
            {
                "parameters": {"foo": "bar"},
                "schedule": {
                    "cron": "*/5 * * * *",
                    "day_or": True,
                    "timezone": "America/New_York",
                },
            },
        ],
    }
)

# Get the updated Flow resp and assert the parameters are present
updated_deployment_resp = prefect_client.get(url=f"deployments/name/{flow_name}/{deployment_name}")
updated_deployment_json = updated_deployment_resp.json()
assert len(updated_deployment_json["schedules"]) == 1
assert updated_deployment_json["schedules"][0]["parameters"] == {"foo": "bar"}
This results in a schedule in the response that does not have any
parameters
populated. Everything else for the schedule is present, though. Patching new values for
cron
,
day_or
, or
timezone
updates the schedule as one would expect. When passing
parameters
with
slug
, the
parameters
do update. Lastly, when passing in an empty array for
schedules
, the schedules are not deleted (but this might be intended).
@Nate, let me know if you need anything else for this. Happy to provide responses and any additional examples.
n
i haven't had the time to look at this, if you're pretty confident its a bug then please feel free to open an issue otherwise ill look at this when/if i can
j
I think the "zeroing out" of
parameters
is a bug. I'll open an issue for that. Not sure about the rest, though.
🙏 1