anxkhn opened a new pull request, #69401:
URL: https://github.com/apache/airflow/pull/69401

   
   Any Dag scheduled with the Task SDK ``EventsTimetable``
   (``from airflow.sdk import EventsTimetable``) currently fails to serialize 
with
   ``SerializationError: Failed to serialize DAG '...': '_summary'``, so the Dag
   cannot be parsed or scheduled.
   
   The SDK timetable serializer in 
``airflow-core/src/airflow/serialization/encoders.py``
   emits only ``{event_dates, restrict_to_events, description}`` and drops the
   ``_summary`` key, but the core ``EventsTimetable.deserialize`` in
   ``airflow-core/src/airflow/timetables/events.py`` read ``data["_summary"]``
   unconditionally and raised ``KeyError`` when it was absent. The two are
   asymmetric: ``_summary`` became a required serialized field in #51203, and 
the
   SDK serializer that omits it was added in #58669 ("Implement timetables in
   SDK"), so on ``main`` today an SDK ``EventsTimetable`` round-trips into a 
crash.
   
   This makes ``deserialize`` fall back to the summary already computed by
   ``EventsTimetable.__init__`` (``"{n} events"`` when there is no description,
   otherwise the description) when ``_summary`` is not present in the serialized
   data. Dags using the SDK timetable serialize and schedule again, and existing
   serialized data that still carries ``_summary`` keeps its stored value.
   
   A parametrized regression test round-trips a Dag scheduled with the SDK
   ``EventsTimetable`` through ``DagSerialization`` (with and without a 
description)
   and asserts the summary is preserved; it fails with the ``KeyError`` before 
the
   change and passes after.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [ ] Yes
   
   ## Final diff (3 files, +35/-2)
   1. `airflow-core/src/airflow/timetables/events.py:140` (one production line):
      `timetable._summary = data["_summary"]` ->
      `timetable._summary = data.get("_summary", timetable._summary)`.
   2. `airflow-core/tests/unit/serialization/test_dag_serialization.py`: adds
      `EventsTimetable` to the existing `airflow.sdk` import block, and adds
      `test_dag_roundtrip_from_sdk_events_timetable` (parametrized 
`no-description` /
      `with-description`, `@pytest.mark.db_test`) in the `TestStringifiedDAGs`
      round-trip class, next to the sibling `test_dag_roundtrip_from_timetable`.
   3. `airflow-core/newsfragments/69283.bugfix.rst`: one-line `.bugfix` note
      (filename to be renamed to the real PR number at ship time).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to