Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecations from Slack Provider #44693

Merged
merged 3 commits into from
Dec 6, 2024
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
14 changes: 14 additions & 0 deletions providers/src/airflow/providers/slack/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
Changelog
---------

main
....

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

* Removed deprecated ``SqlToSlackOperator``. Use ``SqlToSlackWebhookOperator`` instead.
* Removed deprecated ``send_file`` method from hooks. Use ``send_file_v2`` or ``send_file_v1_to_v2`` instead.
* Removed deprecated module lack_notifier.py. Use ``airflow.providers.slack.notifications.slack`` instead.
* Define method parameter as empty string or None is deprecated.
* Removed deprecated parameter ``slack_conn_id`` from ``SqlToSlackWebhookOperator``. Use ``slack_webhook_conn_id`` instead.


8.9.2
.....

Expand Down
64 changes: 1 addition & 63 deletions providers/src/airflow/providers/slack/hooks/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, TypedDict

from deprecated import deprecated
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
from typing_extensions import NotRequired

from airflow.exceptions import AirflowNotFoundException, AirflowProviderDeprecationWarning
from airflow.exceptions import AirflowNotFoundException
from airflow.hooks.base import BaseHook
from airflow.providers.slack.utils import ConnectionExtraConfig
from airflow.utils.helpers import exactly_one
Expand Down Expand Up @@ -186,67 +185,6 @@ def call(self, api_method: str, **kwargs) -> SlackResponse:
"""
return self.client.api_call(api_method, **kwargs)

@deprecated(
reason=(
"This method utilise `files.upload` Slack API method which is being sunset on March 11, 2025. "
"Beginning May 8, 2024, newly-created apps will be unable to 'files.upload' Slack API. "
"Please use `send_file_v2` or `send_file_v1_to_v2` instead."
),
category=AirflowProviderDeprecationWarning,
)
def send_file(
self,
*,
channels: str | Sequence[str] | None = None,
file: str | Path | None = None,
content: str | None = None,
filename: str | None = None,
filetype: str | None = None,
initial_comment: str | None = None,
title: str | None = None,
**kwargs,
) -> SlackResponse:
"""
Create or upload an existing file.

:param channels: Comma-separated list of channel names or IDs where the file will be shared.
If omitting this parameter, then file will send to workspace.
:param file: Path to file which need to be sent.
:param content: File contents. If omitting this parameter, you must provide a file.
:param filename: Displayed filename.
:param filetype: A file type identifier.
:param initial_comment: The message text introducing the file in specified ``channels``.
:param title: Title of file.

.. seealso::
- `Slack API files.upload method <https://api.slack.com/methods/files.upload>`_
- `File types <https://api.slack.com/types/file#file_types>`_
"""
if not exactly_one(file, content):
raise ValueError("Either `file` or `content` must be provided, not both.")
elif file:
file = Path(file)
with open(file, "rb") as fp:
if not filename:
filename = file.name
return self.client.files_upload(
file=fp,
filename=filename,
filetype=filetype,
initial_comment=initial_comment,
title=title,
channels=channels,
)

return self.client.files_upload(
content=content,
filename=filename,
filetype=filetype,
initial_comment=initial_comment,
title=title,
channels=channels,
)

def send_file_v2(
self,
*,
Expand Down

This file was deleted.

24 changes: 1 addition & 23 deletions providers/src/airflow/providers/slack/operators/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
from __future__ import annotations

import json
import warnings
from collections.abc import Sequence
from functools import cached_property
from typing import TYPE_CHECKING, Any

from typing_extensions import Literal

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.slack.hooks.slack import SlackHook
from airflow.utils.types import NOTSET, ArgNotSet

if TYPE_CHECKING:
from slack_sdk.http_retry import RetryHandler
Expand All @@ -55,21 +52,14 @@ def __init__(
self,
*,
slack_conn_id: str = SlackHook.default_conn_name,
method: str | None = None,
method: str,
api_params: dict | None = None,
base_url: str | None = None,
proxy: str | None = None,
timeout: int | None = None,
retry_handlers: list[RetryHandler] | None = None,
**kwargs,
) -> None:
if not method:
warnings.warn(
"Define `method` parameter as empty string or None is deprecated. "
"In the future it will raise an error on task initialisation.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
super().__init__(**kwargs)
self.slack_conn_id = slack_conn_id
self.method = method
Expand Down Expand Up @@ -234,21 +224,9 @@ def __init__(
content: str | None = None,
title: str | None = None,
method_version: Literal["v1", "v2"] = "v2",
channel: str | Sequence[str] | None | ArgNotSet = NOTSET,
snippet_type: str | None = None,
**kwargs,
) -> None:
if channel is not NOTSET:
warnings.warn(
"Argument `channel` is deprecated and will removed in a future releases. "
"Please use `channels` instead.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
if channels:
raise ValueError(f"Cannot set both arguments: channel={channel!r} and channels={channels!r}.")
channels = channel # type: ignore[assignment]

super().__init__(method="files.upload", **kwargs)
self.channels = channels
self.initial_comment = initial_comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING, Any

from deprecated import deprecated
from typing_extensions import Literal

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning, AirflowSkipException
from airflow.exceptions import AirflowException, AirflowSkipException
from airflow.providers.slack.hooks.slack import SlackHook
from airflow.providers.slack.transfers.base_sql_to_slack import BaseSqlToSlackOperator
from airflow.providers.slack.transfers.sql_to_slack_webhook import SqlToSlackWebhookOperator
from airflow.providers.slack.utils import parse_filename

if TYPE_CHECKING:
Expand Down Expand Up @@ -169,22 +167,3 @@ def execute(self, context: Context) -> None:
initial_comment=self.slack_initial_comment,
title=self.slack_title,
)


@deprecated(
reason=(
"`airflow.providers.slack.transfers.sql_to_slack.SqlToSlackOperator` has been renamed "
"and moved `airflow.providers.slack.transfers.sql_to_slack_webhook.SqlToSlackWebhookOperator` "
"this operator deprecated and will be removed in future"
),
category=AirflowProviderDeprecationWarning,
)
class SqlToSlackOperator(SqlToSlackWebhookOperator):
"""
Executes an SQL statement in a given SQL connection and sends the results to Slack Incoming Webhook.

Deprecated, use :class:`airflow.providers.slack.transfers.sql_to_slack_webhook.SqlToSlackWebhookOperator`
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
# under the License.
from __future__ import annotations

import warnings
from collections.abc import Iterable, Mapping, Sequence
from typing import TYPE_CHECKING, Any

from deprecated import deprecated
from tabulate import tabulate

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.exceptions import AirflowException
from airflow.providers.slack.hooks.slack_webhook import SlackWebhookHook
from airflow.providers.slack.transfers.base_sql_to_slack import BaseSqlToSlackOperator
from airflow.utils.types import NOTSET, ArgNotSet

if TYPE_CHECKING:
from airflow.utils.context import Context
Expand Down Expand Up @@ -89,23 +86,8 @@ def __init__(
slack_message: str,
results_df_name: str = "results_df",
parameters: list | tuple | Mapping[str, Any] | None = None,
slack_conn_id: str | ArgNotSet = NOTSET,
**kwargs,
) -> None:
if slack_conn_id is not NOTSET:
warnings.warn(
"Parameter `slack_conn_id` is deprecated because this attribute initially intend to use with "
"Slack API however this operator provided integration with Slack Incoming Webhook. "
"Please use `slack_webhook_conn_id` instead.",
AirflowProviderDeprecationWarning,
stacklevel=3,
)
if slack_webhook_conn_id and slack_conn_id != slack_webhook_conn_id:
raise ValueError(
"Conflicting Connection ids provided, "
f"slack_webhook_conn_id={slack_webhook_conn_id!r}, slack_conn_id={slack_conn_id!r}."
)
slack_webhook_conn_id = slack_conn_id # type: ignore[assignment]
if not slack_webhook_conn_id:
raise ValueError("Got an empty `slack_webhook_conn_id` value.")
super().__init__(
Expand Down Expand Up @@ -164,14 +146,3 @@ def execute(self, context: Context) -> None:
self._render_and_send_slack_message(context, df)

self.log.debug("Finished sending SQL data to Slack")

@property
@deprecated(
reason=(
"`SqlToSlackWebhookOperator.slack_conn_id` property deprecated and will be removed in a future. "
"Please use `slack_webhook_conn_id` instead."
),
category=AirflowProviderDeprecationWarning,
)
def slack_conn_id(self):
return self.slack_webhook_conn_id
Loading