Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIP-72: Gracefully handle 'not-found' XCOMs in task sdk API client #45344

Merged

Conversation

amoghrajesh
Copy link
Contributor

closes: #45341

Testing results

DAG used:

from airflow import DAG
from airflow.providers.standard.operators.python import PythonOperator

def push_to_xcom(**kwargs):
    value = "Hello, XCom!"
    return value


def pull_from_xcom(**kwargs):
    ti = kwargs['ti']
    xcom_value = ti.xcom_pull(task_ids='invalid_id')
    print(f"Retrieved XCom Value: {xcom_value}")


with DAG(
    'xcom_example',
    schedule=None,
    catchup=False,
) as dag:

    push_xcom_task = PythonOperator(
        task_id='push_xcom_task',
        python_callable=push_to_xcom,
    )

    pull_xcom_task = PythonOperator(
        task_id='pull_xcom_task',
        python_callable=pull_from_xcom,
    )

    push_xcom_task >> pull_xcom_task

Legacy

Task 1 XCom pushed:
image

Task 2 XCom consumed as None when absent:
image

Task SDK

Task 1 XCom pushed:
image

Task 2 XCom consumed as None when absent:
image


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@amoghrajesh amoghrajesh changed the title AIP-72: Gracefully handle not-found XCOMs in task sdk API client AIP-72: Gracefully handle 'not-found' XCOMs in task sdk API client Jan 2, 2025
@amoghrajesh amoghrajesh requested review from kaxil, ashb and jscheffl January 2, 2025 09:55
Copy link
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one comment. But not critical to move ahead.

@amoghrajesh amoghrajesh force-pushed the gracefully-handle-no-xcom-situation branch from 8862d7d to f8e4be0 Compare January 2, 2025 11:00
@amoghrajesh amoghrajesh requested a review from jscheffl January 2, 2025 11:01
Copy link
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, much simpler now :-D

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

@amoghrajesh - can you please rebase that one -> we found and issue with @jscheffl with the new caching scheme - fixed in #45347 that would run "main" version of the tests. I am asking in all affected PRs to rebase.

Copy link
Contributor Author

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uranusjr @jscheffl its already handled using an event hook

task_sdk/src/airflow/sdk/api/client.py Show resolved Hide resolved
@amoghrajesh
Copy link
Contributor Author

@amoghrajesh - can you please rebase that one -> we found and issue with @jscheffl with the new caching scheme - fixed in #45347 that would run "main" version of the tests. I am asking in all affected PRs to rebase.

Oh ok, let me rebase this one

@amoghrajesh
Copy link
Contributor Author

Hi @uranusjr are you ok with the reply on this comment? #45344 (comment)

@amoghrajesh amoghrajesh force-pushed the gracefully-handle-no-xcom-situation branch from 7c807b7 to 482fab5 Compare January 3, 2025 06:38
@amoghrajesh amoghrajesh requested a review from uranusjr January 3, 2025 06:43
@amoghrajesh amoghrajesh merged commit aae1a57 into apache:main Jan 3, 2025
44 checks passed
@amoghrajesh amoghrajesh deleted the gracefully-handle-no-xcom-situation branch January 3, 2025 09:11
LefterisXefteris pushed a commit to LefterisXefteris/airflow that referenced this pull request Jan 5, 2025
…pache#45344)

* AIP-72: Gracefully handle not-found XCOMs in task sdk API client

* re raising exception for non 404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AIP-72: Gracefully handle "not-found" XCOMs in task sdk API client
4 participants