nagasrisai commented on code in PR #64614:
URL: https://github.com/apache/airflow/pull/64614#discussion_r3070365366
##########
task-sdk/tests/task_sdk/execution_time/test_task_runner.py:
##########
@@ -2106,6 +2106,30 @@ def mock_send_side_effect(*args, **kwargs):
),
)
+ def test_xcom_pull_default_respected_when_no_map_indexes(
+ self,
+ create_runtime_ti,
+ mock_supervisor_comms,
+ ):
+ """Test that ``default`` is returned when map_indexes is not specified
and no XCom is found.
+
+ Previously, ``xcoms.append(None)`` was used unconditionally on the
no-map-indexes
+ path, so a user-supplied ``default`` was silently ignored.
+ """
+
+ class CustomOperator(BaseOperator):
+ def execute(self, context):
+ pass
+
+ task = CustomOperator(task_id="pull_task")
+ runtime_ti = create_runtime_ti(task=task)
+
+ with patch.object(XCom, "get_all") as mock_get_all:
+ mock_get_all.return_value = None
+ result = runtime_ti.xcom_pull(key="missing_key",
task_ids="task_a", default="fallback_value")
+
+ assert result == "fallback_value"
+
Review Comment:
Done. Added
`test_xcom_pull_default_fills_correct_position_with_multiple_task_ids` — it
pulls from `["task_with_xcom", "task_without_xcom"]` where the first has a
stored value and the second returns nothing, and checks the result comes back
as `["stored_value", "my_default"]`. That makes it explicit that the default
lands in the right slot and doesn't bleed into positions where there was actual
data. @anishgirianish
--
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]