jason810496 commented on code in PR #76583:
URL: https://github.com/apache/airflow/pull/76583#discussion_r4667555930


##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -648,7 +651,9 @@ async def inner(
                 )
             # Select the id alongside dag_id: a NULL dag_id and a missing row 
both come back
             # as None from a bare ``Log.dag_id`` scalar, and they authorize 
differently.
-            row = session.execute(select(Log.id, Log.dag_id).where(Log.id == 
event_log_id)).one_or_none()
+            row = (
+                await session.execute(select(Log.id, Log.dag_id).where(Log.id 
== event_log_id))
+            ).one_or_none()
             if row is not None and row.dag_id is None:

Review Comment:
   The `requires_access_dag` call below still runs the sync 
`DagModel.get_team_name` on the event loop on a cache miss. #76493 adds 
`get_team_name_async` for the same case.
   
   The unit tests mock `get_team_name`, so they miss this. An 
`event_loop_queries` test with a Dag-linked row would catch it.



##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -627,13 +628,15 @@ async def inner(
 
 def requires_access_event_log(
     method: ResourceMethod,
-) -> Callable[[Request, BaseUser, Session], Coroutine[Any, Any, None]]:
+) -> Callable[[Request, BaseUser, AsyncSession], Coroutine[Any, Any, None]]:
     """Wrap ``requires_access_dag`` and extract the dag_id from the 
event_log_id."""
 
     async def inner(
         request: Request,
         user: GetUserDep,
-        session: SessionDep,
+        # Not the route's sync ``SessionDep``: this dependency runs on the 
event loop, where a sync
+        # pool checkout blocks the requests holding the pooled connections 
from releasing them.
+        session: AsyncSessionDep,

Review Comment:
   On `GET /eventLogs/{event_log_id}`, this session now holds an async 
connection until the sync handler returns. Before, the lookup shared the 
handler's sync session, so this adds a second pooled connection per request.
   
   Could we open a short session around the `Log` lookup instead, as 
`execution_api/security.py` does?
   
   ```python
   async with create_session_async() as session:
       row = (
           await session.execute(select(Log.id, Log.dag_id).where(Log.id == 
event_log_id))
       ).one_or_none()
   ```



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