kaxil commented on code in PR #60108:
URL: https://github.com/apache/airflow/pull/60108#discussion_r2957015411
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -92,18 +94,21 @@
@ti_id_router.patch(
"/{task_instance_id}/run",
status_code=status.HTTP_200_OK,
+ dependencies=[Security(require_auth, scopes=["token:execution",
"token:workload"])],
responses={
status.HTTP_404_NOT_FOUND: {"description": "Task Instance not found"},
status.HTTP_409_CONFLICT: {"description": "The TI is already in the
requested state"},
HTTP_422_UNPROCESSABLE_CONTENT: {"description": "Invalid payload for
the state transition"},
},
response_model_exclude_unset=True,
)
-def ti_run(
+async def ti_run(
Review Comment:
Changing `ti_run` from `def` to `async def` will block the event loop. The
function body does extensive synchronous SQLAlchemy calls (`session.execute()`,
`session.scalars()`, etc.). FastAPI runs sync `def` handlers in a threadpool
automatically, but `async def` handlers run directly on the event loop — so
every synchronous DB call here becomes a blocking operation on the loop.
Since `_jwt_generator` is registered as a sync factory, you can use the sync
`services.get(JWTGenerator)` instead of `await services.aget(JWTGenerator)`,
and keep this function as `def`.
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py:
##########
@@ -282,6 +287,10 @@ def ti_run(
context.next_method = ti.next_method
context.next_kwargs = ti.next_kwargs
+ generator: JWTGenerator = await services.aget(JWTGenerator)
Review Comment:
This token generation block sits inside the `try: ... except
SQLAlchemyError:` block (the `except` is at line 295). If `services.aget()` or
`generator.generate()` raises a non-SQLAlchemy exception, it propagates as an
unhandled 500.
Consider moving these 3 lines after the try/except, right before `return
context`, so only the actual DB operations are covered by the SQLAlchemy catch.
--
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]