Don-Burns commented on code in PR #37150:
URL: https://github.com/apache/airflow/pull/37150#discussion_r1476721918


##########
airflow/providers/common/sql/operators/sql.py:
##########
@@ -1058,9 +1058,13 @@ def __init__(
 
     def execute(self, context: Context):
         hook = self.get_db_hook()
-        result = hook.get_first(self.sql)[0]
-        if not result:
+        result = hook.get_first(self.sql)
+
+        # if the query returns 0 rows result will be None so cannot be indexed 
into
+        if result is None:

Review Comment:
   the `get_first` method on hook will only return the first row though right? 
It is calling `fetchone` on the result set from the DB.
   So there will not be a list but a tuple if there is data or None if no data 
present from the query.
   
   The issue with your change is that if the result of the query is `0` or `""` 
then the condition is trigger giving a false error, which is the context for 
this change.
   
   This behaviour is caught on this condition in the added tests:
   
https://github.com/apache/airflow/blob/009ab3376638eff4eb94f8345be4535b6d30e85b/tests/providers/common/sql/operators/test_sql.py#L909



-- 
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: commits-unsubscr...@airflow.apache.org

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

Reply via email to