pierrejeambrun opened a new pull request, #72699:
URL: https://github.com/apache/airflow/pull/72699
Follow-up to #72554. That PR restored ``.limit(1)`` on the four single-row
XCom
lookups whose ``LIMIT`` was dropped when the code migrated from the legacy
``Query.first()`` to SQLAlchemy 2.0's ``Result.first()`` (which does not add
a
LIMIT of its own — see the ``Result.first`` docstring). A wider audit of the
remaining ``.first()`` calls under ``airflow/api_fastapi/`` turned up two
more
sites with the same shape:
- ``execution_api/routes/task_instances.py::get_previous_task_instance`` —
reads one
previous TI ordered by ``logical_date DESC``, no LIMIT. Without the bound
the
query pulls every earlier matching TI into the Python process and returns
the
first. Introduced in #59712.
- ``core_api/routes/public/dags.py::unfavorite_dag`` — probes
``dag_favorite`` for
the current ``(dag_id, user_id)`` before deletion. The schema bounds the
result
to a single row, so the practical cost here is small, but the pattern is
the
same. Introduced in #51264.
Adding ``.limit(1)`` at both sites and covering each with a regression test
that
inspects the compiled SQL for ``LIMIT 1`` — the test infrastructure is
inlined
because ``capture_orm_selects`` from #72554 has not merged yet; once it lands
both tests can adopt the shared helper.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 4.7)
Generated-by: Claude Code (Opus 4.7) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]