uranusjr commented on code in PR #45344:
URL: https://github.com/apache/airflow/pull/45344#discussion_r1901486394
##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -219,7 +219,24 @@ def get(
params = {}
if map_index is not None:
params.update({"map_index": map_index})
- resp = self.client.get(f"xcoms/{dag_id}/{run_id}/{task_id}/{key}",
params=params)
+ try:
+ resp = self.client.get(f"xcoms/{dag_id}/{run_id}/{task_id}/{key}",
params=params)
+ except ServerResponseError as e:
+ if e.response.status_code == HTTPStatus.NOT_FOUND:
+ log.error(
+ "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)
Review Comment:
No I mean with the current code, if a ServerResponseError that’s not 404 is
raised by the XCom API, this would silently suppress that exception and fall
over the the line after this. Since `resp` is not defined if the `try` block is
unsuccessful, this would result in this function failing with a very unhelpful
`name 'resp' is not defined`. A `raise` statement should be inserted after line
239 to retain the original exception.
--
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]