diff --git a/airflow/hooks/dbapi.py b/airflow/hooks/dbapi.py index 1f898706a5e919..da33bacca84474 100644 --- a/airflow/hooks/dbapi.py +++ b/airflow/hooks/dbapi.py @@ -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) diff --git a/tests/hooks/test_dbapi.py b/tests/hooks/test_dbapi.py index 81a63de441d699..fd2bbd913247a8 100644 --- a/tests/hooks/test_dbapi.py +++ b/tests/hooks/test_dbapi.py @@ -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"