uranusjr commented on code in PR #32883:
URL: https://github.com/apache/airflow/pull/32883#discussion_r1277985239


##########
airflow/utils/scheduler_health.py:
##########
@@ -36,11 +38,11 @@ def do_GET(self):
             try:
                 with create_session() as session:
                     scheduler_job = (
-                        session.query(Job)
+                        session.scalars(select(Job))
                         .filter_by(job_type=SchedulerJobRunner.job_type)
                         .filter_by(hostname=get_hostname())
                         .order_by(Job.latest_heartbeat.desc())
-                        .first()
+                        .limit(1)
                     )

Review Comment:
   Because you mocked the session object; with mock you can literally call 
anything without errors. This fails if you use an actual SQLAlchemy session 
object
   
   ```pycon
   >>> from airflow.utils.db import create_session
   >>> from airflow.models.job import Job
   >>> from sqlalchemy import select
   >>> with create_session() as s:
   ...  s.scalars(select(Job)).filter_by(job_type="SchedulerJob")
   ...
   Traceback (most recent call last):
     File "<stdin>", line 2, in <module>
   AttributeError: 'ScalarResult' object has no attribute 'filter_by'
   ```



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