henry3260 commented on code in PR #66488:
URL: https://github.com/apache/airflow/pull/66488#discussion_r3213281124
##########
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.
Good catch!
--
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]