Skip to content

Commit

Permalink
Remove Provider Deprecations in Yandex provider (apache#44754)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawwar authored Dec 7, 2024
1 parent 558148c commit e786c78
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 136 deletions.
13 changes: 13 additions & 0 deletions providers/src/airflow/providers/yandex/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
Changelog
---------

main
....

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

* removed ``YandexCloudBaseHook.provider_user_agent`` . Use ``utils.user_agent.provider_user_agent`` instead.
* removed ``connection_id`` parameter from ``YandexCloudBaseHook``. Use ``yandex_conn_id`` parameter.
* removed ``yandex.hooks.yandexcloud_dataproc`` module.
* removed ``yandex.operators.yandexcloud_dataproc`` module.
* removed implicit passing of ``yandex_conn_id`` in ``DataprocBaseOperator``. Please pass it as a parameter.

3.12.0
......

Expand Down
24 changes: 2 additions & 22 deletions providers/src/airflow/providers/yandex/hooks/yandex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
# under the License.
from __future__ import annotations

import warnings
from typing import Any

import yandexcloud

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.hooks.base import BaseHook
from airflow.providers.yandex.utils.credentials import (
CredentialsType,
Expand All @@ -38,7 +36,6 @@ class YandexCloudBaseHook(BaseHook):
A base hook for Yandex.Cloud related tasks.
:param yandex_conn_id: The connection ID to use when fetching connection info
:param connection_id: Deprecated, use yandex_conn_id instead
:param default_folder_id: The folder ID to use instead of connection folder ID
:param default_public_ssh_key: The key to use instead of connection key
:param default_service_account_id: The service account ID to use instead of key service account ID
Expand Down Expand Up @@ -96,16 +93,6 @@ def get_connection_form_widgets(cls) -> dict[str, Any]:
),
}

@classmethod
def provider_user_agent(cls) -> str | None:
warnings.warn(
"Using `provider_user_agent` in `YandexCloudBaseHook` is deprecated. "
"Please use it in `utils.user_agent` instead.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
return provider_user_agent()

@classmethod
def get_ui_field_behaviour(cls) -> dict[str, Any]:
"""Return custom UI field behaviour for Yandex connection."""
Expand All @@ -116,21 +103,14 @@ def get_ui_field_behaviour(cls) -> dict[str, Any]:

def __init__(
self,
# connection_id is deprecated, use yandex_conn_id instead
connection_id: str | None = None,
yandex_conn_id: str | None = None,
default_folder_id: str | None = None,
default_public_ssh_key: str | None = None,
default_service_account_id: str | None = None,
) -> None:
super().__init__()
if connection_id:
warnings.warn(
"Using `connection_id` is deprecated. Please use `yandex_conn_id` parameter.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
self.connection_id = yandex_conn_id or connection_id or default_conn_name

self.connection_id = yandex_conn_id or default_conn_name
self.connection = self.get_connection(self.connection_id)
self.extras = self.connection.extra_dejson
self.credentials: CredentialsType = get_credentials(
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions providers/src/airflow/providers/yandex/operators/dataproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
# under the License.
from __future__ import annotations

import warnings
from collections.abc import Iterable, Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.yandex.hooks.dataproc import DataprocHook

Expand Down Expand Up @@ -269,16 +267,6 @@ def __init__(self, *, yandex_conn_id: str | None = None, cluster_id: str | None
def _setup(self, context: Context) -> DataprocHook:
if self.cluster_id is None:
self.cluster_id = context["task_instance"].xcom_pull(key="cluster_id")
if self.yandex_conn_id is None:
xcom_yandex_conn_id = context["task_instance"].xcom_pull(key="yandexcloud_connection_id")
if xcom_yandex_conn_id:
warnings.warn(
"Implicit pass of `yandex_conn_id` is deprecated, please pass it explicitly",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
self.yandex_conn_id = xcom_yandex_conn_id

return DataprocHook(yandex_conn_id=self.yandex_conn_id)

def execute(self, context: Context):
Expand Down

This file was deleted.

42 changes: 0 additions & 42 deletions providers/tests/yandex/hooks/test_yandex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
# under the License.
from __future__ import annotations

import os
from unittest import mock
from unittest.mock import MagicMock

import pytest

yandexcloud = pytest.importorskip("yandexcloud")

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.yandex.hooks.yandex import YandexCloudBaseHook

from tests_common.test_utils.config import conf_vars
Expand Down Expand Up @@ -55,23 +52,6 @@ def test_client_created_without_exceptions(self, mock_get_credentials, mock_get_
)
assert hook.client is not None

@mock.patch("airflow.hooks.base.BaseHook.get_connection")
@mock.patch("airflow.providers.yandex.utils.credentials.get_credentials")
def test_provider_user_agent(self, mock_get_credentials, mock_get_connection):
mock_get_connection.return_value = mock.Mock(yandex_conn_id="yandexcloud_default", extra_dejson="{}")
mock_get_credentials.return_value = {"token": 122323}
sdk_prefix = "MyAirflow"

hook = YandexCloudBaseHook()
with (
conf_vars({("yandex", "sdk_user_agent_prefix"): sdk_prefix}),
pytest.warns(
AirflowProviderDeprecationWarning,
match="Using `provider_user_agent` in `YandexCloudBaseHook` is deprecated. Please use it in `utils.user_agent` instead.",
),
):
assert hook.provider_user_agent().startswith(sdk_prefix)

@mock.patch("airflow.hooks.base.BaseHook.get_connection")
@mock.patch("airflow.providers.yandex.utils.credentials.get_credentials")
def test_sdk_user_agent(self, mock_get_credentials, mock_get_connection):
Expand All @@ -83,28 +63,6 @@ def test_sdk_user_agent(self, mock_get_credentials, mock_get_connection):
hook = YandexCloudBaseHook()
assert hook.sdk._channels._client_user_agent.startswith(sdk_prefix)

@pytest.mark.parametrize(
"uri",
[
pytest.param(
"a://?extra__yandexcloud__folder_id=abc&extra__yandexcloud__public_ssh_key=abc", id="prefix"
),
pytest.param("a://?folder_id=abc&public_ssh_key=abc", id="no-prefix"),
],
)
@mock.patch("airflow.providers.yandex.utils.credentials.get_credentials", new=MagicMock())
def test_backcompat_prefix_works(self, uri):
with (
mock.patch.dict(os.environ, {"AIRFLOW_CONN_MY_CONN": uri}),
pytest.warns(
AirflowProviderDeprecationWarning,
match="Using `connection_id` is deprecated. Please use `yandex_conn_id` parameter.",
),
):
hook = YandexCloudBaseHook("my_conn")
assert hook.default_folder_id == "abc"
assert hook.default_public_ssh_key == "abc"

@mock.patch("airflow.hooks.base.BaseHook.get_connection")
@mock.patch("airflow.providers.yandex.utils.credentials.get_credentials")
def test_get_endpoint_specified(self, mock_get_credentials, mock_get_connection):
Expand Down

0 comments on commit e786c78

Please sign in to comment.