Skip to content

Commit 63d071d

Browse files
zzstoatzzclaude
andauthored
fix: allow Jinja templates in trigger enabled field during YAML loading (#19610)
Co-authored-by: Claude <[email protected]>
1 parent 90fc8dd commit 63d071d

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/prefect/cli/deploy/_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from prefect._experimental.sla.objects import SlaTypes
88
from prefect.client.schemas.actions import DeploymentScheduleCreate
99
from prefect.client.schemas.schedules import SCHEDULE_TYPES
10-
from prefect.events import DeploymentTriggerTypes
1110

1211

1312
class WorkPoolConfig(BaseModel):
@@ -52,7 +51,9 @@ class DeploymentConfig(BaseModel):
5251
work_pool: Optional[WorkPoolConfig] = None
5352

5453
# automations metadata
55-
triggers: Optional[List[DeploymentTriggerTypes]] = None
54+
# Triggers are stored as raw dicts to allow Jinja templating (e.g., enabled: "{{ prefect.variables.is_prod }}")
55+
# Strict validation happens later in _initialize_deployment_triggers after template resolution
56+
triggers: Optional[List[Dict[str, Any]]] = None
5657
sla: Optional[List[SlaTypes]] = None
5758

5859

tests/cli/deploy/test_format_validation_error.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,39 @@ def test_format_validation_error_with_both_top_level_and_deployment_errors():
214214
# Should have both links
215215
assert "https://docs.prefect.io/v3/how-to-guides/deployments/prefect-yaml" in result
216216
assert "https://docs.prefect.io/v3/concepts/deployments#deployment-schema" in result
217+
218+
219+
def test_trigger_with_templated_enabled_field_should_not_raise():
220+
"""
221+
Regression test for issue #19501: triggers with templated 'enabled' field
222+
should be accepted during YAML loading, allowing template resolution later.
223+
224+
The 'enabled' field may contain a Jinja template like
225+
'{{ prefect.variables.deployment_trigger_is_active }}' which will be
226+
resolved to a boolean after variable resolution. The YAML validation
227+
should accept this string and defer strict type validation until after
228+
templating occurs.
229+
"""
230+
raw_data = {
231+
"deployments": [
232+
{
233+
"name": "my-deployment",
234+
"entrypoint": "flow.py:my_flow",
235+
"triggers": [
236+
{
237+
"type": "event",
238+
"enabled": "{{ prefect.variables.deployment_trigger_is_active }}",
239+
"match": {"prefect.resource.id": "hello.world"},
240+
"expect": ["external.resource.pinged"],
241+
}
242+
],
243+
}
244+
]
245+
}
246+
247+
# This should NOT raise a validation error - the trigger should be accepted
248+
# as a raw dict and validated later after template resolution
249+
model = PrefectYamlModel.model_validate(raw_data)
250+
assert len(model.deployments) == 1
251+
assert model.deployments[0].triggers is not None
252+
assert len(model.deployments[0].triggers) == 1

0 commit comments

Comments
 (0)