Sanketp1997 opened a new issue, #41098:
URL: https://github.com/apache/airflow/issues/41098

   ### Apache Airflow version
   
   Other Airflow 2 version (please specify below)
   
   ### If "Other Airflow 2 version" selected, which one?
   
   2.8.4+astro.3
   
   ### What happened?
   
   A task's XCom value is cleared when a task is rescheduled after being 
deferred.
   
   ### What you think should happen instead?
   
   XCom should not be cleared in this case, as it is still the same task run.
   
   ### How to reproduce
   
   `
   import logging
   from datetime import datetime, timezone
   
   from airflow import DAG
   from airflow.decorators import task
   from airflow.operators.python import get_current_context
   from airflow.sensors.base import PokeReturnValue
   
   with DAG(
       dag_id="defer_behavior_test",
       schedule=None,
       start_date=datetime(2024, 7, 1, tzinfo=timezone.utc),
       catchup=False,
       concurrency=1,
       max_active_runs=1,
       default_view="graph",
   ):
   
       @task.sensor(
           poke_interval=10,
           timeout=60,
           mode="reschedule",
       )
       def should_defer_once():
           ctx = get_current_context()
           ti = ctx.get("ti")
           xcom_content = ti.xcom_pull(key="xcom_content")
           if xcom_content is not None and xcom_content != "" and xcom_content 
!= "None":
               logging.info(f"xcom_content: {xcom_content}")
               return PokeReturnValue(True)
           else:
               logging.info("xcom_content not available")
               logging.info(f"xcom_content: {xcom_content}")
           ti.xcom_push(key="xcom_content", value="Dummy XCOM content")
           logging.info("Pushed dummy XCOM content")
           return PokeReturnValue(False)
   
       @task(trigger_rule="all_done")
       def check_xcom_content():
           ctx = get_current_context()
           ti = ctx.get("ti")
           xcom_content = ti.xcom_pull(key="xcom_content")
           logging.info(f"xcom_content: {xcom_content}")
   
       should_defer_once() >> check_xcom_content()
   `
   
   ### Operating System
   
   macOS
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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