Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DowngradeUpstreamMapIndexes(VersionChange):
description = __doc__

instructions_to_migrate_to_previous_version = (
schema(TIRunContext).field("upstream_map_indexes").had(type=dict[str, int] | None), # type: ignore
schema(TIRunContext).field("upstream_map_indexes").had(type=dict[str, int | None] | None),
)

@convert_response_to_previous_version_for(TIRunContext) # type: ignore[arg-type]
Expand All @@ -40,13 +40,14 @@ def downgrade_upstream_map_indexes(response: ResponseInfo = None) -> None: # ty
"""
resp = response.body.get("upstream_map_indexes")
if isinstance(resp, dict):
downgraded = {}
downgraded: dict[str, int | list | None] = {}
for k, v in resp.items():
if isinstance(v, int):
downgraded[k] = v
elif isinstance(v, list) and v and all(isinstance(i, int) for i in v):
downgraded[k] = v[0]
else:
# for cases like None, make it -1
downgraded[k] = -1
# Keep values like None as is — the Task SDK expects them unchanged during mapped task expansion,
# and modifying them can cause unexpected failures.
downgraded[k] = None
response.body["upstream_map_indexes"] = downgraded
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ def teardown_method(self):
{"task_a": 3, "task_b": 9},
id="list of ints",
),
pytest.param(
[
("task_a", None),
],
{"task_a": None},
id="task has no upstreams",
),
pytest.param(
[("task_a", None), ("task_b", [6, 7]), ("task_c", 2)],
{"task_a": -1, "task_b": 6, "task_c": 2},
{"task_a": None, "task_b": 6, "task_c": 2},
id="mixed types",
),
],
Expand Down