This is an automated email from the ASF dual-hosted git repository.
ashb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 11e9387c7d0 Validate the timetable of Dags from Lang-SDK runtimes
(#77304)
11e9387c7d0 is described below
commit 11e9387c7d0fc1a67979497f098d9947e4bea1a2
Author: Adam Postek <[email protected]>
AuthorDate: Fri Nov 20 21:34:39 2026 +0000
Validate the timetable of Dags from Lang-SDK runtimes (#77304)
Signed-off-by: Adam <[email protected]>
---
.../src/airflow/serialization/serialized_objects.py | 13 +++++++++++--
.../tests/unit/serialization/test_dag_serialization.py | 11 +++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/airflow-core/src/airflow/serialization/serialized_objects.py
b/airflow-core/src/airflow/serialization/serialized_objects.py
index 9fa366537b2..ff3f3b7c78c 100644
--- a/airflow-core/src/airflow/serialization/serialized_objects.py
+++ b/airflow-core/src/airflow/serialization/serialized_objects.py
@@ -48,7 +48,12 @@ from airflow._shared.module_loading import qualname
from airflow._shared.timezones.timezone import from_timestamp, parse_timezone,
utcnow
from airflow.callbacks.callback_requests import DagCallbackRequest,
TaskCallbackRequest
from airflow.configuration import conf
-from airflow.exceptions import AirflowException, DeserializationError,
SerializationError
+from airflow.exceptions import (
+ AirflowException,
+ AirflowTimetableInvalid,
+ DeserializationError,
+ SerializationError,
+)
from airflow.models.connection import Connection
from airflow.models.expandinput import SchedulerMappedArgument,
create_expand_input
from airflow.models.taskinstancekey import TaskInstanceKey
@@ -2182,7 +2187,7 @@ class DagSerialization(BaseSerialization):
"""
Check that a serialized Dag, such as one a Lang-SDK runtime produced,
can be stored and loaded.
- It must match the JSON schema, have unique task ids and deserialize
with a timetable and complete
+ It must match the JSON schema, have unique task ids and deserialize
with a valid timetable and complete
deadline alert definitions. Like a Dag built with the SDK, it must not
set a ``max_active_runs``
its timetable forbids, nor ``catchup`` without a ``start_date``, and
its task graph must have no
cycle. *serialized_obj* is not changed.
@@ -2224,6 +2229,10 @@ class DagSerialization(BaseSerialization):
) from e
if timetable is None:
raise DeserializationError(dag_id, f"Dag {dag_id!r} has no
timetable")
+ try:
+ timetable.validate()
+ except AirflowTimetableInvalid as e:
+ raise DeserializationError(dag_id, f"Dag {dag_id!r} has an invalid
timetable: {e}") from e
if (limit := timetable.active_runs_limit) is not None and
deserialized.max_active_runs > limit:
raise DeserializationError(
dag_id,
diff --git a/airflow-core/tests/unit/serialization/test_dag_serialization.py
b/airflow-core/tests/unit/serialization/test_dag_serialization.py
index 34b4376796a..881824eb5aa 100644
--- a/airflow-core/tests/unit/serialization/test_dag_serialization.py
+++ b/airflow-core/tests/unit/serialization/test_dag_serialization.py
@@ -5350,6 +5350,17 @@ class TestValidateSerializedDag:
with pytest.raises(DeserializationError, match="^Dag 'checked_dag' has
no timetable$"):
DagSerialization.validate_serialized_dag(data)
+ def test_rejects_an_invalid_timetable(self):
+ data = self._serialize()
+ data["dag"]["timetable"] = {
+ "__type": "airflow.timetables.interval.CronDataIntervalTimetable",
+ "__var": {"expression": "0 25 * * *", "timezone": "UTC"},
+ }
+
+ error = "Dag 'checked_dag' has an invalid timetable: [0 25 * * *] is
not acceptable, out of range"
+ with pytest.raises(DeserializationError,
match=f"^{re.escape(error)}$"):
+ DagSerialization.validate_serialized_dag(data)
+
@pytest.mark.parametrize(
("deadline", "error"),
[