Don-Burns commented on code in PR #37150:
URL: https://github.com/apache/airflow/pull/37150#discussion_r1477026393
##########
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:
After thinking some more,
the most surefire solution might be to try index in and catch the Index/Type
error that will be raised if index 0 is out of bound for an empty list or a
None type respectively. The end result is similar and avoids multiple
condition checks on the happy path that my other approach had.
```python
try:
result = result[0]
except (TypeError, IndexError):
...
```
Let me know what you think.
--
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]