uranusjr commented on code in PR #76825:
URL: https://github.com/apache/airflow/pull/76825#discussion_r4599669571


##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -668,35 +668,80 @@ def get(
         *,
         previous_iteration: bool = False,
     ) -> XComResponse:
-        """Get a XCom value from the API server."""
+        """
+        Get a XCom value from the API server.
+
+        Any *map_index* is sent as given. An omitted one reads the task's 
result: its value, or for a
+        mapped task the values of all its instances as a list.
+        """
         params: dict[str, str | int] = {}
         if previous_iteration:
             params["previous_iteration"] = True
-        if map_index is not None and map_index >= 0:
-            params.update({"map_index": map_index})
+        if map_index is not None:
+            params["map_index"] = map_index
         if include_prior_dates:
             params.update({"include_prior_dates": include_prior_dates})
         try:
             resp = self.client.get(_path("xcoms", dag_id, run_id, task_id, 
tail=key), params=params)
         except ServerResponseError as e:
-            if e.response.status_code == HTTPStatus.NOT_FOUND:
-                log.debug(
-                    "XCom not found",
-                    dag_id=dag_id,
-                    run_id=run_id,
-                    task_id=task_id,
-                    key=key,
-                    map_index=map_index,
-                    detail=e.detail,
-                    status_code=e.response.status_code,
-                )
-                # Airflow 2.x just ignores the absence of an XCom and moves on 
with a return value of None
-                # Hence returning with key as `key` and value as `None`, so 
that the message is sent back to task runner
-                # and the default value of None in xcom_pull is used.
-                return XComResponse(key=key, value=None)
-            raise
+            if e.response.status_code != HTTPStatus.NOT_FOUND:
+                raise
+            log.debug(
+                "XCom not found",
+                dag_id=dag_id,
+                run_id=run_id,
+                task_id=task_id,
+                key=key,
+                map_index=map_index,
+                detail=e.detail,
+                status_code=e.response.status_code,
+            )
+            value = self._get_mapped_values_or_none(
+                dag_id,
+                run_id,
+                task_id,
+                key,
+                map_index,
+                include_prior_dates=include_prior_dates,
+                previous_iteration=previous_iteration,
+            )

Review Comment:
   Done



-- 
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