schizophrenicmaniac opened a new pull request, #74247:
URL: https://github.com/apache/airflow/pull/74247

   FastAPI validates a sync route's response in the threadpool but serializes 
it on the event loop. Two public API responses were still hitting the database 
during serialization, so when the SQLAlchemy pool was exhausted the whole API 
server stalled on the pool checkout until `pool_timeout` expired.
   
   - `DAGDetailsResponse.latest_dag_version` was a computed field that opened 
its own session to load the latest DagVersion. `get_dag_details` now loads it 
through the request session and sets it on the model, like `is_favorite` and 
`active_runs_count`, and `latest_dag_version` is a regular field. This also 
drops the second connection each `/details` request was taking.
   - `PoolCollectionResponse.pools` was `Iterable[PoolResponse]`, which 
pydantic validates lazily during serialization, so the six slot queries per 
pool ran inside `dump_json`. It is now `list[PoolResponse]`, so they run when 
the route builds the response in the threadpool.
   
   In the OpenAPI schema `latest_dag_version` stays required and nullable, but 
it is no longer marked `readOnly`. I regenerated the spec, the UI client and 
the airflow-ctl datamodels.
   
   The new tests record SQL statements executed on the event loop thread while 
serving `/dags/{dag_id}/details` and `/pools`. Without the change they catch 1 
and 24 statements respectively.
   
   closes: #74239
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [ ] Yes (please specify the tool below)
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.


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