prabhusneha commented on code in PR #45802:
URL: https://github.com/apache/airflow/pull/45802#discussion_r1925154674
##########
airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -135,9 +135,16 @@ def get_mapped_task_instances(
"map_index",
"try_number",
"logical_date",
+ "data_interval_start",
+ "data_interval_end",
"rendered_map_index",
],
TI,
+ to_replace={
+ "logical_date": DagRun.logical_date,
Review Comment:
Without aliasing `logical_date` it throws a Programming Error:
```
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error
at or near "ASC"
LINE 7: ...d = task_instance.run_id AND dag_run.logical_date ASC), task..
```
This is because it created a subquery to sort on. The aliasing was added to
avoid this. More details in the SQLAlchemy doc -
https://docs.sqlalchemy.org/en/20/orm/extensions/associationproxy.html#querying-with-association-proxies
query with order by when logical_date is not aliased-
```
...
ORDER BY CASE WHEN (EXISTS (SELECT 1
FROM dag_run
WHERE dag_run.dag_id = task_instance.dag_id AND dag_run.run_id =
task_instance.run_id AND dag_run.logical_date IS NOT NULL))
THEN %(param_1)s ELSE %(param_2)s END, EXISTS (SELECT 1
FROM dag_run
WHERE dag_run.dag_id = task_instance.dag_id AND dag_run.run_id =
task_instance.run_id AND dag_run.logical_date ASC), task_instance.id ASC
LIMIT %(param_3)s OFFSET %(param_4)s
```
--
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]