Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix bug where schedules without a slug or active raise a 500 #17091

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/prefect/server/models/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def create_deployment(
schedules=[
schemas.actions.DeploymentScheduleCreate(
schedule=schedule.schedule,
active=schedule.active, # type: ignore[call-arg]
active=schedule.active,
parameters=schedule.parameters,
slug=schedule.slug,
)
Expand Down Expand Up @@ -274,11 +274,12 @@ async def update_deployment(
schedules=[
schemas.actions.DeploymentScheduleCreate(
schedule=schedule.schedule,
active=schedule.active, # type: ignore[call-arg]
active=schedule.active if schedule.active is not None else True,
parameters=schedule.parameters,
slug=schedule.slug,
)
for schedule in schedules
if schedule.schedule is not None
],
)

Expand Down
54 changes: 54 additions & 0 deletions tests/server/orchestration/api/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,60 @@ async def test_update_deployment_with_multiple_schedules_and_existing_slugs(
}
assert expected_interval_active_and_slug == interval_active_and_slug

async def test_update_schedule_without_slug_and_specifying_active_defaults_to_true(
self,
client,
flow,
):
"""When a schedule is provided without active or a slug, active should default to true."""
schedule1 = schemas.schedules.IntervalSchedule(
interval=datetime.timedelta(days=1)
)
schedule2 = schemas.schedules.IntervalSchedule(
interval=datetime.timedelta(days=2)
)
data = DeploymentCreate(
name="My Deployment",
version="mint",
flow_id=flow.id,
schedules=[
schemas.actions.DeploymentScheduleCreate(
schedule=schedule1,
active=False,
),
],
enforce_parameter_schema=False,
).model_dump(mode="json")

response = await client.post(
"/deployments/",
json=data,
)
assert response.status_code == 201

deployment_id = response.json()["id"]

update_data = schemas.actions.DeploymentUpdate(
schedules=[
schemas.actions.DeploymentScheduleUpdate(
schedule=schedule2,
),
],
).model_dump(mode="json", exclude_unset=True)

response = await client.patch(
f"/deployments/{deployment_id}",
json=update_data,
)
assert response.status_code == 204, response.text

response = await client.get(
f"/deployments/{deployment_id}",
)
assert response.status_code == 200
assert len(response.json()["schedules"]) == 1
assert response.json()["schedules"][0]["active"] is True

async def test_update_deployment_with_multiple_schedules_and_existing_slugs_422(
self,
client,
Expand Down