kaxil commented on code in PR #77114:
URL: https://github.com/apache/airflow/pull/77114#discussion_r4608494156
##########
task-sdk/tests/task_sdk/importers/yaml_importer/test_migrator.py:
##########
@@ -137,7 +137,70 @@ def test_known_version_does_not_warn(recwarn):
def test_migrate_is_noop_at_head_for_the_real_bundle():
body = {"$schema": HEAD_SCHEMA, "dag_id": "d", "tasks": []}
- assert migrator.get_migrator().resolve_and_migrate(body) is body # one
version -> no copy
+ assert migrator.get_migrator().resolve_and_migrate(body) is body # at
head -> no copy
+
+
+def _migrate_from_2026_10_30(**extra):
+ body = {"$schema": migrator.schema_from_version("2026-10-30"), "dag_id":
"d", **extra}
+ return migrator.get_migrator().resolve_and_migrate(body)
+
+
[email protected](
+ ("old", "new"),
+ [
+ pytest.param({"$x": {"task": "a", "key": "k"}}, {"$x": "a", "key":
"k"}, id="x-keyed"),
+ pytest.param({"$xcom": {"task": "a", "key": "k"}}, {"$xcom": "a",
"key": "k"}, id="xcom-keyed"),
+ pytest.param({"$x": {"task": "a"}}, {"$x": "a"}, id="x-task-only"),
+ pytest.param({"$x": {"task": "a", "key": None}}, {"$x": "a"},
id="x-null-key"),
+ pytest.param({"$x": "a"}, {"$x": "a"}, id="x-short-unchanged"),
+ pytest.param([1, {"$x": {"task": "a", "key": "k"}}], [1, {"$x": "a",
"key": "k"}], id="in-list"),
+ pytest.param(
+ {"env": {"V": {"$x": {"task": "a", "key": "k"}}}},
+ {"env": {"V": {"$x": "a", "key": "k"}}},
+ id="in-mapping",
+ ),
+ pytest.param(
+ {"$const": {"$x": {"task": "a", "key": "k"}}},
+ {"$const": {"$x": {"task": "a", "key": "k"}}},
+ id="const-untouched",
+ ),
+ pytest.param(
+ {"$x": {"task": "a", "nope": 1}},
+ {"$x": {"task": "a", "nope": 1}},
+ id="invalid-left-for-validation",
+ ),
+ ],
+)
[email protected]("field", ["with", "run"])
+def test_2027_02_28_flattens_keyed_xcom_in_tasks(field, old, new):
+ out = _migrate_from_2026_10_30(tasks=[{"id": "t", field: {"v": old}}])
+ assert out["tasks"] == [{"id": "t", field: {"v": new}}]
+
+
+def test_2027_02_28_flattens_keyed_xcom_in_templates():
+ out = _migrate_from_2026_10_30(
+ templates={"base": {"with": {"v": {"$x": {"task": "a", "key": "k"}}},
"retries": 2}},
+ tasks=[],
+ )
+ assert out["templates"] == {"base": {"with": {"v": {"$x": "a", "key":
"k"}}, "retries": 2}}
+
+
+def test_2027_02_28_leaves_other_task_keys_alone():
+ task = {"id": "t", "doc_md": {"$x": {"task": "a", "key": "k"}}, "with": {}}
+ out = _migrate_from_2026_10_30(tasks=[task])
+ assert out["tasks"] == [task]
+
+
+def test_2027_02_28_handles_shared_nodes():
+ shared = {"v": {"$x": {"task": "a", "key": "k"}}}
+ body = {
+ "$schema": migrator.schema_from_version("2026-10-30"),
+ "dag_id": "d",
+ "tasks": [{"id": "t1", "with": shared}, {"id": "t2", "with": shared}],
Review Comment:
I think this still passes if `_flatten_xcom_refs` mutates in place, since
the second visit sees an already-flat dict and `resolve_and_migrate` deepcopies
the input first. Could `shared` go under `with` and a key the converter skips
(`doc_md`, like the test above), with an assert that the skipped one keeps the
old form?
##########
task-sdk/src/airflow/sdk/importers/yaml_importer/models.py:
##########
@@ -183,28 +202,28 @@ class XComRef(_MarkerRef):
"""An upstream task's XCom output."""
_marker_keys = XCOM_KEYS
+ _operand_field = "target"
- target: str | XComTarget = Field(
+ target: str = Field(
Review Comment:
A Dag that bumps `$schema` to 2027-02-28 but keeps `{$x: {task: up, key:
rows}}` now fails with a bare `Input should be a valid string` on `$x`, with
nothing pointing at the new form. The docs example now shows the 2027-02-28
URL, so "change the URL, keep the body" is the likely upgrade path. Could a
dict operand with `task` get a targeted error naming `{$x: up, key: rows}`, the
way `default_args` does in `_reject_deferred`? A line in yaml-dags.rst saying
2026-10-30 files are migrated automatically would help too.
##########
task-sdk/tests/task_sdk/importers/yaml_importer/test_parser.py:
##########
@@ -584,14 +665,14 @@ def test_valid_shapes_round_trip(body):
pytest.param("{$tempalte: x}", id="unknown-template-typo"), #
codespell:ignore tempalte
pytest.param("{cfg: {$weird: 1}}", id="dollar-key-nested"),
pytest.param("{$x: up, $xcom: up}", id="two-marker-keys"),
- pytest.param("{$x: {task: up, nope: 1}}", id="xcom-target-extra-key"),
+ pytest.param("{$x: up, nope: 1}", id="xcom-unknown-option"),
Review Comment:
Now that `$x` takes options, this is the same case as `marker-plus-extra`
above (an unknown option on `$x`), so one of them can go.
--
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]