This is an automated email from the ASF dual-hosted git repository.
ashb pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new d0c27d920e2 [v3-4-test] Validate the timetable of Dags from Lang-SDK
runtimes (#77304) (#77561)
d0c27d920e2 is described below
commit d0c27d920e202b1ba138afb433f4ce6b25e9c254
Author: Adam Postek <[email protected]>
AuthorDate: Tue Nov 24 22:53:11 2026 +0000
[v3-4-test] Validate the timetable of Dags from Lang-SDK runtimes (#77304)
(#77561)
---
.../src/airflow/serialization/serialized_objects.py | 17 +++++++++++++----
.../tests/unit/serialization/test_dag_serialization.py | 11 +++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/airflow-core/src/airflow/serialization/serialized_objects.py
b/airflow-core/src/airflow/serialization/serialized_objects.py
index 1893918861d..f679f23a3ee 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
@@ -2169,9 +2174,9 @@ 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.
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.
+ It must match the JSON schema, have unique task ids and deserialize
with a valid timetable. 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.
:return: The deserialized Dag.
:raises DeserializationError: if it does not.
@@ -2199,6 +2204,10 @@ class DagSerialization(BaseSerialization):
raise DeserializationError(
dag_id, f"Dag {dag_id!r} cannot be deserialized:
{type(cause).__name__}: {cause}"
) from e
+ 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 3c638955da2..bd0f40603c6 100644
--- a/airflow-core/tests/unit/serialization/test_dag_serialization.py
+++ b/airflow-core/tests/unit/serialization/test_dag_serialization.py
@@ -5317,6 +5317,17 @@ class TestValidateSerializedDag:
with pytest.raises(DeserializationError, match=f"^{re.escape(error)}"):
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)
+
def test_returns_the_deserialized_dag(self):
dag = DagSerialization.validate_serialized_dag(self._serialize())