ricky-chaoju commented on code in PR #59918:
URL: https://github.com/apache/airflow/pull/59918#discussion_r2700668485


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -2432,19 +2432,23 @@ def _get_num_times_stuck_in_queued(self, ti: 
TaskInstance, session: Session = NE
             .limit(1)
         )
 
-        query = session.query(Log).where(
-            Log.task_id == ti.task_id,
-            Log.dag_id == ti.dag_id,
-            Log.run_id == ti.run_id,
-            Log.map_index == ti.map_index,
-            Log.try_number == ti.try_number,
-            Log.event == TASK_STUCK_IN_QUEUED_RESCHEDULE_EVENT,
+        statement = (
+            select(func.count())
+            .select_from(Log)

Review Comment:
   Thanks for the suggestion! I tested both approaches:
   Current approach:
   ```select(func.count()).select_from(Log).where(...)```
   Generates:
   ```SELECT count(*) FROM log WHERE ...```
   
   Separated approach:
   ```
   statement = select(Log).where(...)
   select(func.count(statement)).select_from(Log)
   ```
   Generates:
   ```SELECT count((SELECT log.id, log.task_id FROM log WHERE ...)) FROM log```
   
   This triggers a SQLAlchemy warning about implicit coercion and produces 
unexpected SQL.
   
   The current approach generates the cleanest and most efficient query. What 
do you think? Please correct me if I'm wrong.



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