diff --git a/airflow/providers/exasol/hooks/exasol.py b/airflow/providers/exasol/hooks/exasol.py index 784c57cde0661..88ff1b77205ef 100644 --- a/airflow/providers/exasol/hooks/exasol.py +++ b/airflow/providers/exasol/hooks/exasol.py @@ -164,6 +164,10 @@ def run( with closing(conn.execute(query, parameters)) as cur: results = [] + if cur.result_type != "resultSet": + # can't be iterated over + break + if handler is not None: cur = handler(cur) diff --git a/tests/providers/exasol/hooks/test_exasol.py b/tests/providers/exasol/hooks/test_exasol.py index bf85465629c43..3440693e60111 100644 --- a/tests/providers/exasol/hooks/test_exasol.py +++ b/tests/providers/exasol/hooks/test_exasol.py @@ -137,6 +137,15 @@ def test_run_no_queries(self): self.db_hook.run(sql=[]) assert err.value.args[0] == "List of SQL statements is empty" + def test_no_result_set(self): + """Queries like DROP and SELECT are of type rowCount (not resultSet), + which raises an error in pyexasol if trying to iterate over them""" + self.cur.result_type = mock.Mock() + self.cur.result_type.return_value = 'rowCount' + + sql = 'SQL' + self.db_hook.run(sql) + def test_bulk_load(self): with pytest.raises(NotImplementedError): self.db_hook.bulk_load('table', '/tmp/file')