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 Redis #44633

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
11 changes: 11 additions & 0 deletions providers/src/airflow/providers/redis/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
Changelog
---------

main
.....

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

* Hooks

* Removed ``ssl_cert_file`` parameter from ``RedisHook``. Use ``ssl_certfile`` instead

3.8.0
.....

Expand Down
14 changes: 1 addition & 13 deletions providers/src/airflow/providers/redis/hooks/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

from __future__ import annotations

import warnings
from typing import Any

from redis import Redis

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

DEFAULT_SSL_CERT_REQS = "required"
Expand All @@ -37,7 +35,7 @@ class RedisHook(BaseHook):

You can set your db in the extra field of your connection as ``{"db": 3}``.
Also you can set ssl parameters as:
``{"ssl": true, "ssl_cert_reqs": "require", "ssl_cert_file": "/path/to/cert.pem", etc}``.
``{"ssl": true, "ssl_cert_reqs": "require", "ssl_certfile": "/path/to/cert.pem", etc}``.
"""

conn_name_attr = "redis_conn_id"
Expand Down Expand Up @@ -81,16 +79,6 @@ def get_conn(self):
]
ssl_args = {name: val for name, val in conn.extra_dejson.items() if name in ssl_arg_names}

# This logic is for backward compatibility only
if "ssl_cert_file" in conn.extra_dejson and "ssl_certfile" not in conn.extra_dejson:
warnings.warn(
"Extra parameter `ssl_cert_file` deprecated and will be removed "
"in a future release. Please use `ssl_certfile` instead.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
ssl_args["ssl_certfile"] = conn.extra_dejson.get("ssl_cert_file")

if not self.redis:
self.log.debug(
'Initializing redis object for conn_id "%s" on %s:%s:%s',
Expand Down
74 changes: 16 additions & 58 deletions providers/tests/redis/hooks/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@

import pytest

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import Connection
from airflow.providers.redis.hooks.redis import RedisHook

pytestmark = pytest.mark.db_test


class TestRedisHook:
deprecation_message = (
"Extra parameter `ssl_cert_file` deprecated and will be removed "
"in a future release. Please use `ssl_certfile` instead."
)

def test_get_conn(self):
hook = RedisHook(redis_conn_id="redis_default")
assert hook.redis is None
Expand All @@ -47,24 +41,26 @@ def test_get_conn(self):
@mock.patch("airflow.providers.redis.hooks.redis.Redis")
@mock.patch(
"airflow.providers.redis.hooks.redis.RedisHook.get_connection",
return_value=Connection(
)
def test_get_conn_with_extra_config(self, mock_get_connection, mock_redis):
connection = Connection(
login="user",
password="password",
host="remote_host",
port=1234,
extra="""{
"db": 2,
"ssl": true,
"ssl_cert_reqs": "required",
"ssl_ca_certs": "/path/to/custom/ca-cert",
"ssl_keyfile": "/path/to/key-file",
"ssl_certfile": "/path/to/cert-file",
"ssl_check_hostname": true
}""",
),
)
def test_get_conn_with_extra_config(self, mock_get_connection, mock_redis):
connection = mock_get_connection.return_value
)
connection.set_extra(
"""{
"db": 2,
"ssl": true,
"ssl_cert_reqs": "required",
"ssl_ca_certs": "/path/to/custom/ca-cert",
"ssl_keyfile": "/path/to/key-file",
"ssl_certfile": "/path/to/cert-file",
"ssl_check_hostname": true
}"""
)
mock_get_connection.return_value = connection
hook = RedisHook()

hook.get_conn()
Expand All @@ -82,44 +78,6 @@ def test_get_conn_with_extra_config(self, mock_get_connection, mock_redis):
ssl_check_hostname=connection.extra_dejson["ssl_check_hostname"],
)

@mock.patch("airflow.providers.redis.hooks.redis.Redis")
@mock.patch(
"airflow.providers.redis.hooks.redis.RedisHook.get_connection",
return_value=Connection(
password="password",
host="remote_host",
port=1234,
extra="""{
"db": 2,
"ssl": true,
"ssl_cert_reqs": "required",
"ssl_ca_certs": "/path/to/custom/ca-cert",
"ssl_keyfile": "/path/to/key-file",
"ssl_cert_file": "/path/to/cert-file",
"ssl_check_hostname": true
}""",
),
)
def test_get_conn_with_deprecated_extra_config(self, mock_get_connection, mock_redis):
connection = mock_get_connection.return_value
hook = RedisHook()

with pytest.warns(AirflowProviderDeprecationWarning, match=self.deprecation_message):
hook.get_conn()
mock_redis.assert_called_once_with(
host=connection.host,
password=connection.password,
username=None,
port=connection.port,
db=connection.extra_dejson["db"],
ssl=connection.extra_dejson["ssl"],
ssl_cert_reqs=connection.extra_dejson["ssl_cert_reqs"],
ssl_ca_certs=connection.extra_dejson["ssl_ca_certs"],
ssl_keyfile=connection.extra_dejson["ssl_keyfile"],
ssl_certfile=connection.extra_dejson["ssl_cert_file"],
ssl_check_hostname=connection.extra_dejson["ssl_check_hostname"],
)

def test_get_conn_password_stays_none(self):
hook = RedisHook(redis_conn_id="redis_default")
hook.get_conn()
Expand Down