amoghrajesh opened a new pull request, #48440:
URL: https://github.com/apache/airflow/pull/48440

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   closes: #48408 
   
   
   The issue has nothing much to do with cross dags, it wont matter at all.
   
   The root of the problem was that None was returned because 
`include_prior_dates` wasn't implemented in task sdk.
   
   This PR attempts to do that.
   
   ## Key changes
   
   1. Moving away from the `xcom_query` as now I need to pass runtime parameter 
to it, include_prior_dates. Although it is used by other API so not removing it
   2. `logical_date` is a field that marks the start of a data interval and for 
manual runs, can be empty, leading to the functionality of filtering by prior 
dates failing. The query was:
   ```
               dr = session.query(DagRun.logical_date).filter(DagRun.run_id == 
run_id).subquery()
               query = query.filter(cls.logical_date <= dr.c.logical_date)
   ```
   This was running into an issue because `logical_date` was empty for manual 
runs.
   
   Note, this has changed since 2.10.x as we used to have "execution_date" back 
then which wasnt empty.
   
   2.10.x:
   ![image 
(28)](https://github.com/user-attachments/assets/9085d2fa-d781-4ecb-b0cc-df6218561260)
   
   3.0:
   ![image 
(29)](https://github.com/user-attachments/assets/64484da0-706e-421a-9977-869abcefc949)
   
   
   So a good fallback would be to use `run_after` instead when the 
`logical_date` is None. I have implemented that using `coalesce`.
   
   3. Added the `include_prior_dates` as a parameter for the SDK client
   
   
   ## Testing
   
   Used the dag:
   ```
   # from airflow.sdk import dag
   from airflow.decorators import dag, task
   
   
   @dag()
   def cross_dag_xcom_upstream():
       @task
       def push_to_xcom():
           return "Hello!"
   
       push_to_xcom()
   
   
   cross_dag_xcom_upstream()
   
   
   @dag()
   def cross_dag_xcom_downstream():
       @task
       def pull_from_xcom(**context):
           print("The context task instance is", context["task_instance"])
   
           my_data = context["task_instance"].xcom_pull(
               dag_id="cross_dag_xcom_upstream",
               task_ids="push_to_xcom",
               key="return_value",
               include_prior_dates=True,
           )
           return my_data
   
       pull_from_xcom()
   
   
   cross_dag_xcom_downstream()
   
   ```
   
   
   Run the first DAG:
   
   <img width="1726" alt="image" 
src="https://github.com/user-attachments/assets/2f728ca4-b64f-4d53-9fc9-f7596ab31a8e";
 />
   
   
   Run the second DAG:
   
   <img width="1726" alt="image" 
src="https://github.com/user-attachments/assets/38122234-4c72-48ff-be18-e3ca2ebb47c6";
 />
   
   
   Observe that it doesn't get None anymore.
   
   <!-- 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 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to