You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/04/29 04:11:51 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #15585: `func.sum` may returns `Decimal` that break rest APIs.

uranusjr commented on a change in pull request #15585:
URL: https://github.com/apache/airflow/pull/15585#discussion_r622720825



##########
File path: airflow/models/pool.py
##########
@@ -161,12 +161,12 @@ def occupied_slots(self, session: Session):
         """
         from airflow.models.taskinstance import TaskInstance  # Avoid circular import
 
-        return (
+        return int((
             session.query(func.sum(TaskInstance.pool_slots))
             .filter(TaskInstance.pool == self.pool)
             .filter(TaskInstance.state.in_(list(EXECUTION_STATES)))
             .scalar()
-        ) or 0
+        ) or 0)

Review comment:
       `0` does not need to be converted, so I’d just cast the query part:
   
   ```python
   return int(
       session.query(func.sum(TaskInstance.pool_slots))
       .filter(TaskInstance.pool == self.pool)
       .filter(TaskInstance.state.in_(list(EXECUTION_STATES)))
       .scalar()
   ) or 0
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org