jason810496 commented on code in PR #66488:
URL: https://github.com/apache/airflow/pull/66488#discussion_r3212996706


##########
airflow-core/tests/unit/dag_processing/test_collection.py:
##########
@@ -101,31 +102,59 @@ def test_statement_latest_runs_one_dag():
 
 
 @pytest.mark.db_test
-def test_statement_latest_runs_partitioned_sorted_by_partition_date(dag_maker, 
session):
-    with dag_maker("fake-dag", schedule=None):
-        pass
-    dag_maker.sync_dagbag_to_db()
+def test_statement_latest_runs_loads_timetable_fields(session):
+    logical_date = tz.datetime(2025, 1, 1)
+    run_after = tz.datetime(2025, 1, 2)
+
+    session.add(
+        DagRun(
+            dag_id="fake-dag",
+            run_id="latest-run",
+            logical_date=logical_date,
+            data_interval=(logical_date, run_after),
+            run_type=DagRunType.SCHEDULED,
+            run_after=run_after,
+        )
+    )
+    session.flush()
+
+    latest = session.scalar(_get_latest_runs_stmt("fake-dag"))
+    assert latest is not None
+    assert {"run_after", "partition_date", 
"partition_key"}.isdisjoint(sa_inspect(latest).unloaded)
+    assert latest.run_after == run_after
+    assert latest.partition_key is None
+    assert latest.partition_date is None

Review Comment:
   Worthwhile to fix the suggestion from Codex.
   
   ---
   
   Expire the inserted DagRun before asserting loaded fields.
   
     Because this test inserts the `DagRun` and then queries it from the same 
SQLAlchemy session, `session.scalar(...)` can reuse the identity-mapped object 
that was just flushed. In that case `sa_inspect(latest).unloaded` is already 
empty even if `_get_latest_runs_stmt()` or 
`_get_latest_runs_stmt_partitioned()` still defer `run_after` / `partition_*`, 
so the new assertions can pass without actually catching a future lazy-load 
regression. Expiring/expunging the rows or querying in a fresh session would 
make this check real.



##########
airflow-core/src/airflow/dag_processing/collection.py:
##########
@@ -165,8 +168,11 @@ def _get_latest_runs_stmt_partitioned(dag_id: str) -> 
Select:
             load_only(
                 DagRun.dag_id,
                 DagRun.logical_date,
+                DagRun.run_after,

Review Comment:
   If I check the downstream references to `_get_latest_runs_stmt` and 
`_get_latest_runs_stmt_partitioned` correct. They don't access `run_after` at 
all.



##########
airflow-core/tests/unit/dag_processing/test_collection.py:
##########
@@ -101,31 +102,59 @@ def test_statement_latest_runs_one_dag():
 
 
 @pytest.mark.db_test
-def test_statement_latest_runs_partitioned_sorted_by_partition_date(dag_maker, 
session):
-    with dag_maker("fake-dag", schedule=None):
-        pass
-    dag_maker.sync_dagbag_to_db()
+def test_statement_latest_runs_loads_timetable_fields(session):
+    logical_date = tz.datetime(2025, 1, 1)
+    run_after = tz.datetime(2025, 1, 2)
+
+    session.add(
+        DagRun(
+            dag_id="fake-dag",
+            run_id="latest-run",
+            logical_date=logical_date,
+            data_interval=(logical_date, run_after),
+            run_type=DagRunType.SCHEDULED,
+            run_after=run_after,
+        )
+    )
+    session.flush()
+
+    latest = session.scalar(_get_latest_runs_stmt("fake-dag"))
+    assert latest is not None
+    assert {"run_after", "partition_date", 
"partition_key"}.isdisjoint(sa_inspect(latest).unloaded)
+    assert latest.run_after == run_after
+    assert latest.partition_key is None
+    assert latest.partition_date is None
+
 
[email protected]_test
+def test_statement_latest_runs_partitioned_sorted_by_partition_date(session):
     for i, (run_id, partition_key, partition_date) in enumerate(
         (
             ("newest-partition-date", "2025-01-02", tz.datetime(2025, 1, 2)),
             ("older-partition-date", "2025-01-01", tz.datetime(2025, 1, 1)),
             ("null-partition-date", "not-a-time-based-partition", None),
         )
     ):
-        dag_maker.create_dagrun(

Review Comment:
   May I ask why do we need to change the existing test case here?



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