Skip to content

Commit 12fd825

Browse files
zzstoatzzclaude
andauthored
fix: exclude unset grace_period_seconds from deployment concurrency_options (#19784)
Co-authored-by: Claude <[email protected]>
1 parent 97d3356 commit 12fd825

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/prefect/client/orchestration/_deployments/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def create_deployment(
157157
payload["version_info"] = deployment_create.version_info.model_dump(
158158
mode="json"
159159
)
160+
if deployment_create.concurrency_options:
161+
payload["concurrency_options"] = (
162+
deployment_create.concurrency_options.model_dump(
163+
mode="json", exclude_unset=True
164+
)
165+
)
160166

161167
try:
162168
response = self.request("POST", "/deployments/", json=payload)
@@ -823,6 +829,12 @@ async def create_deployment(
823829
payload["version_info"] = deployment_create.version_info.model_dump(
824830
mode="json"
825831
)
832+
if deployment_create.concurrency_options:
833+
payload["concurrency_options"] = (
834+
deployment_create.concurrency_options.model_dump(
835+
mode="json", exclude_unset=True
836+
)
837+
)
826838

827839
try:
828840
response = await self.request("POST", "/deployments/", json=payload)

tests/client/schemas/test_concurrency.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,31 @@ def test_collision_strategy_cancel_new(self):
9292
"""Test that collision_strategy can be set to CANCEL_NEW."""
9393
config = ConcurrencyLimitConfig(limit=1, collision_strategy="CANCEL_NEW")
9494
assert config.collision_strategy == "CANCEL_NEW"
95+
96+
97+
class TestConcurrencyOptionsSerialization:
98+
"""Tests for ConcurrencyOptions serialization behavior.
99+
100+
Regression tests for https://github.com/PrefectHQ/prefect/issues/19778
101+
"""
102+
103+
def test_grace_period_seconds_excluded_when_unset(self):
104+
"""Test that grace_period_seconds is excluded when not explicitly set.
105+
106+
When grace_period_seconds is not provided, model_dump(exclude_unset=True)
107+
should not include it in the output. This prevents API 422 errors.
108+
"""
109+
options = ConcurrencyOptions(collision_strategy="ENQUEUE")
110+
payload = options.model_dump(mode="json", exclude_unset=True)
111+
112+
assert "grace_period_seconds" not in payload
113+
114+
def test_grace_period_seconds_included_when_set(self):
115+
"""Test that grace_period_seconds IS included when explicitly set."""
116+
options = ConcurrencyOptions(
117+
collision_strategy="ENQUEUE", grace_period_seconds=120
118+
)
119+
payload = options.model_dump(mode="json", exclude_unset=True)
120+
121+
assert "grace_period_seconds" in payload
122+
assert payload["grace_period_seconds"] == 120

0 commit comments

Comments
 (0)