diff --git a/src/prefect/server/models/deployments.py b/src/prefect/server/models/deployments.py index 685e789151d2..ae291cef5ef1 100644 --- a/src/prefect/server/models/deployments.py +++ b/src/prefect/server/models/deployments.py @@ -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, ) @@ -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 ], ) diff --git a/tests/server/orchestration/api/test_deployments.py b/tests/server/orchestration/api/test_deployments.py index 1273cc172d04..88542f102c17 100644 --- a/tests/server/orchestration/api/test_deployments.py +++ b/tests/server/orchestration/api/test_deployments.py @@ -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,