You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "shubhamraj-git (via GitHub)" <gi...@apache.org> on 2025/02/05 10:00:12 UTC

[PR] Add update XCom endpoint in RestAPI [airflow]

shubhamraj-git opened a new pull request, #46457:
URL: https://github.com/apache/airflow/pull/46457

   related: https://github.com/apache/airflow/issues/45966
   
   Debugging Airflow workflows often involves dealing with incorrect or missing XCom values, which can cause tasks to fail or behave unexpectedly. 
   Traditionally, fixing such issues requires rerunning tasks, modifying Dag logic, or even manually editing the Airflow metadata database—none of which are ideal in a production setting. With API-based XCom updates, users can quickly correct erroneous values without restarting entire workflows. 
   This is especially useful in long-running jobs, where reprocessing can be costly, or in dependency-heavy pipelines, where a single incorrect value can block multiple downstream tasks. By allowing targeted updates, this feature speeds up debugging, reduces downtime, and ensures smoother workflow execution.
   
   -----------------------------------
   
   ### Steps to play around the feature.
   
   Add the following Dag.
   ```
   from datetime import datetime, timedelta
   from airflow import DAG
   from airflow.operators.python import PythonOperator
   import time
   
   def push_xcom_value(ti):
       value_to_push = "Hello from XCom!"
       ti.xcom_push(key='my_key', value=value_to_push)
       time.sleep(60)  # Wait for 1 minute, meanwhile you can update the XCom via API
   
   def pull_xcom_value(ti):
       pulled_value = ti.xcom_pull(task_ids='push_task', key='my_key')
       print(f"Pulled Value: {pulled_value}") # Updated value should be present
   
   default_args = {
       'owner': 'airflow',
       'catchup': False,
       'start_date': datetime(2024, 2, 5),
   }
   
   dag = DAG(
       'xcom_push_pull_dag',
       default_args=default_args,
       description='A simple DAG to demonstrate XCom push and pull',
       catchup=False,
   )
   
   push_task = PythonOperator(
       task_id='push_task',
       python_callable=push_xcom_value,
       dag=dag,
   )
   
   pull_task = PythonOperator(
       task_id='pull_task',
       python_callable=pull_xcom_value,
       dag=dag,
   )
   
   push_task >> pull_task
   
   ```
   As soon as push_task has pushed to xcom, just update the value via API.
   http://localhost:29091/docs#/XCom/update_xcom_entry
   
   <img width="1416" alt="image" src="https://github.com/user-attachments/assets/47bb5e5c-2574-448a-9f43-a029f71c8a2f" />
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   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](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add update XCom endpoint in RestAPI [airflow]

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal merged PR #46457:
URL: https://github.com/apache/airflow/pull/46457


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org