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


##########
airflow/hooks/dbapi.py:
##########
@@ -188,25 +206,21 @@ def run(self, sql, autocommit=False, parameters=None, 
handler=None):
                 self.set_autocommit(conn, autocommit)
 
             with closing(conn.cursor()) as cur:
-                results = []
                 for sql_statement in sql:
+                    results = []
                     self._run_command(cur, sql_statement, parameters)
                     if handler is not None:
                         result = handler(cur)
                         results.append(result)

Review Comment:
   Simply moving `results = []` into the loop is wrong because it makes 
`execute` always return a list with a single element, which is wrong. The 
correct behaviour is
   
   1. If the input is a list of strs, return a list containing results from 
each str.
       i. If a str in the list contains one single query, add the query’s 
result to the returning list.
       ii. If a str in the list contains multiple queries, add the result of 
the last query in the str to the returning list.
   2. If the input is a str containing one single SQL query, return the query’s 
result.
   3. If the input is a str containing multiple queries, return the last 
query’s result.
   
   Item 3 is the thing talked about in the linked comment, but this change 
modifies the behaviour of the first scenario.



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