Skip to content

Commit

Permalink
Refresh session when deleting schedules off a deployment (#17278)
Browse files Browse the repository at this point in the history
  • Loading branch information
cicdw authored Feb 27, 2025
1 parent b498b9d commit c5eef21
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/prefect/server/models/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,12 +1012,16 @@ async def delete_schedules_for_deployment(
deployment_id: a deployment id
"""

deployment = await session.get(db.Deployment, deployment_id)
assert deployment is not None

result = await session.execute(
sa.delete(db.DeploymentSchedule).where(
db.DeploymentSchedule.deployment_id == deployment_id
)
)

await session.refresh(deployment)
return result.rowcount > 0


Expand Down
39 changes: 39 additions & 0 deletions tests/server/orchestration/api/test_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,45 @@ async def test_paginate_deployments_returns_empty_list(self, client):


class TestUpdateDeployment:
async def test_update_deployment_with_schedule_allows_addition_of_concurrency(
self, client, deployment
):
"""
Regression test for https://github.com/PrefectHQ/prefect/issues/17227
"""
# ensure there's a schedule
update_data = DeploymentUpdate(
schedules=[
schemas.actions.DeploymentScheduleUpdate(
schedule=schemas.schedules.IntervalSchedule(
interval=datetime.timedelta(days=1)
),
active=True,
)
]
).model_dump(mode="json", exclude_unset=True)

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

# no slug so that it deletes and recreates the schedule
update_again = DeploymentUpdate(
schedules=[
schemas.actions.DeploymentScheduleUpdate(
schedule=schemas.schedules.IntervalSchedule(
interval=datetime.timedelta(days=1)
),
active=True,
)
],
concurrency_limit=4, # add a limit
).model_dump(mode="json", exclude_unset=True)

response = await client.patch(
f"/deployments/{deployment.id}", json=update_again
)
assert response.status_code == 204

async def test_update_deployment_enforces_parameter_schema(
self,
deployment_with_parameter_schema,
Expand Down

0 comments on commit c5eef21

Please sign in to comment.