Skip to content

Commit

Permalink
Remove Provider Deprecations in Common SQL (apache#44645)
Browse files Browse the repository at this point in the history
* Remove Provider Deprecations in Common SQL

* Fix Changelog header

Co-authored-by: Jens Scheffler <[email protected]>

---------

Co-authored-by: Jens Scheffler <[email protected]>
  • Loading branch information
2 people authored and Ohashiro committed Dec 6, 2024
1 parent 4cbfad0 commit 14953ee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 33 deletions.
10 changes: 10 additions & 0 deletions providers/src/airflow/providers/common/sql/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
Changelog
---------

main
.....

.. warning::
All deprecated classes, parameters and features have been removed from the Common SQL provider package.
The following breaking changes were introduced:

* Hooks
* Remove ``_make_serializable`` method from ``DbApiHook``. Use ``_make_common_data_structure`` instead.

1.20.0
......

Expand Down
12 changes: 0 additions & 12 deletions providers/src/airflow/providers/common/sql/hooks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from airflow.exceptions import (
AirflowException,
AirflowOptionalProviderFeatureException,
AirflowProviderDeprecationWarning,
)
from airflow.hooks.base import BaseHook

Expand Down Expand Up @@ -502,17 +501,6 @@ def _make_common_data_structure(self, result: T | Sequence[T]) -> tuple | list[t
If this method is not overridden, the result data is returned as-is. If the output of the cursor
is already a common data structure, this method should be ignored.
"""
# Back-compatibility call for providers implementing old ´_make_serializable' method.
with contextlib.suppress(AttributeError):
result = self._make_serializable(result=result) # type: ignore[attr-defined]
warnings.warn(
"The `_make_serializable` method is deprecated and support will be removed in a future "
f"version of the common.sql provider. Please update the {self.__class__.__name__}'s provider "
"to a version based on common.sql >= 1.9.1.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)

if isinstance(result, Sequence):
return cast(list[tuple], result)
return cast(tuple, result)
Expand Down
19 changes: 0 additions & 19 deletions providers/tests/common/sql/hooks/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@

import logging
import logging.config
import warnings
from unittest.mock import MagicMock

import pytest

from airflow.config_templates.airflow_local_settings import DEFAULT_LOGGING_CONFIG
from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import Connection
from airflow.providers.common.sql.hooks.sql import DbApiHook, fetch_all_handler
from airflow.utils.session import provide_session
Expand Down Expand Up @@ -238,23 +236,6 @@ def test_no_query(self, empty_statement):
dbapi_hook.run(sql=empty_statement)
assert err.value.args[0] == "List of SQL statements is empty"

@pytest.mark.db_test
def test_make_common_data_structure_hook_has_deprecated_method(self):
"""If hook implements ``_make_serializable`` warning should be raised on call."""
hook = mock_hook(DbApiHook)
hook._make_serializable = lambda result: result
with pytest.warns(
AirflowProviderDeprecationWarning, match="`_make_serializable` method is deprecated"
):
hook._make_common_data_structure(["foo", "bar", "baz"])

@pytest.mark.db_test
def test_make_common_data_structure_no_deprecated_method(self):
"""If hook not implements ``_make_serializable`` there is no warning should be raised on call."""
with warnings.catch_warnings():
warnings.simplefilter("error", AirflowProviderDeprecationWarning)
mock_hook(DbApiHook)._make_common_data_structure(["foo", "bar", "baz"])

@pytest.mark.db_test
def test_placeholder_config_from_extra(self):
dbapi_hook = mock_hook(DbApiHook, conn_params={"extra": {"placeholder": "?"}})
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/pre_commit/check_common_sql_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def is_subclass_of_dbapihook(node: ast.ClassDef) -> bool:
return False


def has_make_serializable_method(node: ast.ClassDef) -> bool:
def has_make_common_data_structure_method(node: ast.ClassDef) -> bool:
"""Return True if the given class implements `_make_common_data_structure` method."""
for body_element in node.body:
if isinstance(body_element, ast.FunctionDef) and (body_element.name == MAKE_COMMON_METHOD_NAME):
Expand Down Expand Up @@ -98,7 +98,7 @@ def check_sql_providers_dependency():
continue

for clazz in get_classes(path):
if is_subclass_of_dbapihook(node=clazz) and has_make_serializable_method(node=clazz):
if is_subclass_of_dbapihook(node=clazz) and has_make_common_data_structure_method(node=clazz):
provider_yaml_path: str = determine_provider_yaml_path(file_path=path)
provider_metadata: dict = get_yaml_content(file_path=provider_yaml_path)

Expand Down

0 comments on commit 14953ee

Please sign in to comment.