Skip to content

Commit

Permalink
refactor: Added deprecation warning for executemany parameter in inse…
Browse files Browse the repository at this point in the history
…rt_rows method of DbApiHook
  • Loading branch information
davidblain-infrabel committed Apr 8, 2024
1 parent 92775af commit 1369944
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions airflow/providers/common/sql/hooks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,16 @@ def insert_rows(
:param commit_every: The maximum number of rows to insert in one
transaction. Set to 0 to insert all rows in one transaction.
:param replace: Whether to replace instead of insert
:param executemany: Deprecated. It will be removed in future Airflow versions as inserts are always
executed using the executemany method.
"""
if kwargs.get("executemany"):
warnings.warn(
"executemany parameter is deprecated, as executemany will always be used to insert rows.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)

with closing(self.get_conn()) as conn:
if self.supports_autocommit:
self.set_autocommit(conn, False)
Expand Down
1 change: 1 addition & 0 deletions tests/deprecations_ignore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@
- tests/providers/cncf/kubernetes/test_pod_generator.py::TestPodGenerator::test_pod_name_confirm_to_max_length
- tests/providers/cncf/kubernetes/test_pod_generator.py::TestPodGenerator::test_pod_name_is_valid
- tests/providers/cncf/kubernetes/test_template_rendering.py::test_render_k8s_pod_yaml
- tests/providers/common/sql/hooks/test_dbapi.py::TestDbApiHook::test_insert_rows_replace_executemany_hana_dialect
- tests/providers/common/sql/hooks/test_dbapi.py::TestDbApiHook::test_instance_check_works_for_legacy_db_api_hook
- tests/providers/common/sql/operators/test_sql.py::TestSQLCheckOperatorDbHook::test_get_hook
- tests/providers/common/sql/operators/test_sql.py::TestSqlBranch::test_branch_false_with_dag_run
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/common/sql/hooks/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_insert_rows_replace_executemany_hana_dialect(self):
table = "table"
rows = [("hello",), ("world",)]

self.db_hook.insert_rows(table, rows, replace=True)
self.db_hook.insert_rows(table, rows, replace=True, executemany=True)

assert self.conn.close.call_count == 1
assert self.cur.close.call_count == 1
Expand Down

0 comments on commit 1369944

Please sign in to comment.