Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions airflow/hooks/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ def run(self, sql, autocommit=False, parameters=None, handler=None):
if scalar:
sql = [sql]

if sql:
self.log.debug("Executing %d statements", len(sql))
else:
raise ValueError("List of SQL statements is empty")

with closing(self.get_conn()) as conn:
if self.supports_autocommit:
self.set_autocommit(conn, autocommit)
Expand Down
5 changes: 5 additions & 0 deletions tests/hooks/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,8 @@ def handler(cur):
assert called == 2
assert self.conn.commit.called
assert result == [obj, obj]

def test_run_no_queries(self):
with pytest.raises(ValueError) as err:
self.db_hook.run(sql=[])
assert err.value.args[0] == "List of SQL statements is empty"