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 Provider Deprecations in Apprise #44764

Merged
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/apprise/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 {provider_name} provider package.
The following breaking changes were introduced:

* Hooks
* Parameter ``tag`` cannot be None. It is not set to MATCH_ALL_TAG as default.
* Notifications
* Parameter ``notify_type`` cannot be None. It is not set to NotifyType.INFO as default.
* Parameter ``body_format`` cannot be None. It is not set to NotifyFormat.TEXT as default.
* Parameter ``tag`` cannot be None. It is not set to MATCH_ALL_TAG as default.

1.4.1
.....

Expand Down
12 changes: 1 addition & 11 deletions providers/src/airflow/providers/apprise/hooks/apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
from __future__ import annotations

import json
import warnings
from collections.abc import Iterable
from typing import TYPE_CHECKING, Any

import apprise
from apprise import AppriseConfig, NotifyFormat, NotifyType

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.hooks.base import BaseHook

if TYPE_CHECKING:
Expand Down Expand Up @@ -77,7 +75,7 @@ def notify(
title: str | None = None,
notify_type: NotifyType = NotifyType.INFO,
body_format: NotifyFormat = NotifyFormat.TEXT,
tag: str | Iterable[str] | None = None,
tag: str | Iterable[str] = "all",
attach: AppriseAttachment | None = None,
interpret_escapes: bool | None = None,
config: AppriseConfig | None = None,
Expand All @@ -97,14 +95,6 @@ def notify(
sequences such as \n and \r to their respective ascii new-line and carriage return characters
:param config: Specify one or more configuration
"""
if tag is None:
warnings.warn(
"`tag` cannot be None. Assign it to be MATCH_ALL_TAG",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
tag = "all"

title = title or ""

apprise_obj = apprise.Apprise()
Expand Down
32 changes: 3 additions & 29 deletions providers/src/airflow/providers/apprise/notifications/apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

from __future__ import annotations

import warnings
from collections.abc import Iterable
from functools import cached_property

from apprise import AppriseConfig, NotifyFormat, NotifyType

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.notifications.basenotifier import BaseNotifier
from airflow.providers.apprise.hooks.apprise import AppriseHook

Expand Down Expand Up @@ -53,38 +51,14 @@ def __init__(
*,
body: str,
title: str | None = None,
notify_type: NotifyType | None = None,
body_format: NotifyFormat | None = None,
tag: str | Iterable[str] | None = None,
notify_type: NotifyType = NotifyType.INFO,
body_format: NotifyFormat = NotifyFormat.TEXT,
tag: str | Iterable[str] = "all",
attach: str | None = None,
interpret_escapes: bool | None = None,
config: AppriseConfig | None = None,
apprise_conn_id: str = AppriseHook.default_conn_name,
):
if tag is None:
warnings.warn(
"`tag` cannot be None. Assign it to be MATCH_ALL_TAG",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
tag = "all"

if notify_type is None:
warnings.warn(
"`notify_type` cannot be None. Assign it to be NotifyType.INFO",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
notify_type = NotifyType.INFO

if body_format is None:
warnings.warn(
"`body_format` cannot be None. Assign it to be NotifyFormat.TEXT",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
body_format = NotifyFormat.TEXT

super().__init__()
self.apprise_conn_id = apprise_conn_id
self.body = body
Expand Down
4 changes: 1 addition & 3 deletions providers/tests/apprise/hooks/test_apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pytest
from apprise import NotifyFormat, NotifyType

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import Connection
from airflow.providers.apprise.hooks.apprise import AppriseHook

Expand Down Expand Up @@ -114,8 +113,7 @@ def test_notify(self, connection):
apprise_obj.add = MagicMock()
with patch.object(apprise, "Apprise", return_value=apprise_obj):
hook = AppriseHook()
with pytest.warns(AirflowProviderDeprecationWarning):
hook.notify(body="test")
hook.notify(body="test")

apprise_obj.notify.assert_called_once_with(
body="test",
Expand Down
31 changes: 7 additions & 24 deletions providers/tests/apprise/notifications/test_apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import pytest
from apprise import NotifyFormat, NotifyType

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.operators.empty import EmptyOperator
from airflow.providers.apprise.notifications.apprise import (
AppriseNotifier,
Expand All @@ -37,8 +36,7 @@ class TestAppriseNotifier:
def test_notifier(self, mock_apprise_hook, dag_maker):
with dag_maker("test_notifier") as dag:
EmptyOperator(task_id="task1")
with pytest.warns(AirflowProviderDeprecationWarning):
notifier = send_apprise_notification(body="DISK at 99%", notify_type=NotifyType.FAILURE)
notifier = send_apprise_notification(body="DISK at 99%", notify_type=NotifyType.FAILURE)
notifier({"dag": dag})
mock_apprise_hook.return_value.notify.assert_called_once_with(
body="DISK at 99%",
Expand All @@ -55,8 +53,7 @@ def test_notifier(self, mock_apprise_hook, dag_maker):
def test_notifier_with_notifier_class(self, mock_apprise_hook, dag_maker):
with dag_maker("test_notifier") as dag:
EmptyOperator(task_id="task1")
with pytest.warns(AirflowProviderDeprecationWarning):
notifier = AppriseNotifier(body="DISK at 99%", notify_type=NotifyType.FAILURE)
notifier = AppriseNotifier(body="DISK at 99%", notify_type=NotifyType.FAILURE)
notifier({"dag": dag})
mock_apprise_hook.return_value.notify.assert_called_once_with(
body="DISK at 99%",
Expand All @@ -74,12 +71,11 @@ def test_notifier_templated(self, mock_apprise_hook, dag_maker):
with dag_maker("test_notifier") as dag:
EmptyOperator(task_id="task1")

with pytest.warns(AirflowProviderDeprecationWarning):
notifier = AppriseNotifier(
notify_type=NotifyType.FAILURE,
title="DISK at 99% {{dag.dag_id}}",
body="System can crash soon {{dag.dag_id}}",
)
notifier = AppriseNotifier(
notify_type=NotifyType.FAILURE,
title="DISK at 99% {{dag.dag_id}}",
body="System can crash soon {{dag.dag_id}}",
)
context = {"dag": dag}
notifier(context)
mock_apprise_hook.return_value.notify.assert_called_once_with(
Expand All @@ -92,16 +88,3 @@ def test_notifier_templated(self, mock_apprise_hook, dag_maker):
interpret_escapes=None,
config=None,
)

@mock.patch("airflow.providers.apprise.notifications.apprise.AppriseHook")
def test_apprise_deprecation_warnning(self, mock_apprise_hook):
with pytest.warns(AirflowProviderDeprecationWarning) as record:
AppriseNotifier(
title="DISK at 99% {{dag.dag_id}}",
body="System can crash soon {{dag.dag_id}}",
)
assert len(record) == 3

assert record[0].message.args[0] == "`tag` cannot be None. Assign it to be MATCH_ALL_TAG"
assert record[1].message.args[0] == "`notify_type` cannot be None. Assign it to be NotifyType.INFO"
assert record[2].message.args[0] == "`body_format` cannot be None. Assign it to be NotifyFormat.TEXT"