uranusjr commented on code in PR #61464:
URL: https://github.com/apache/airflow/pull/61464#discussion_r2844434989
##########
airflow-core/src/airflow/models/backfill.py:
##########
@@ -218,17 +219,29 @@ def validate_sort_ordinal(self, key: str, val: int) ->
int:
return val
-def _get_latest_dag_run_row_query(*, dag_id: str, info: DagRunInfo, session:
Session):
+def _get_latest_dag_run_row_query(*, dag_id: str, info: DagRunInfo):
from airflow.models import DagRun
+ if info.partition_key:
+ return (
+ select(DagRun)
+ .where(
+ DagRun.dag_id == dag_id,
+ DagRun.partition_key == info.partition_key,
+ )
+ .order_by(
+ DagRun.start_date.is_(None),
+ DagRun.start_date.desc(),
+ )
+ .limit(1)
+ )
return (
select(DagRun)
.where(
- DagRun.logical_date == info.logical_date,
DagRun.dag_id == dag_id,
+ DagRun.logical_date == info.logical_date,
)
- .order_by(nulls_first(DagRun.start_date.desc(), session=session))
- .limit(1)
+ .limit(1) # not really necessary since uniqueness constraint, but hey
Review Comment:
Probably simpler to rewrite this entire function to
```python
stmt = select(DagRun).where(DagRun.dag_id == dag_id)
if info.partition_key is not None:
stmt = stmt.where(DagRun.partition_key == info.partition_key)
if info.logical_date is not None:
stmt = stmt.where(DagRun.logical_date == info.logical_date)
stmt = stmt.order_by(DagRun.start_date.is_(None), DagRun.start_date.desc())
return stmt.limit(1) # not really necessary since uniqueness constraint,
but hey
```
--
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]