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 incorrect deprecation warning in secrets backend #22326

Merged
merged 1 commit into from
Mar 17, 2022
Merged
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
26 changes: 17 additions & 9 deletions airflow/secrets/base_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.
import warnings
from abc import ABC
from contextlib import suppress
from typing import TYPE_CHECKING, List, Optional

if TYPE_CHECKING:
Expand Down Expand Up @@ -86,17 +85,26 @@ def get_connection(self, conn_id: str) -> Optional['Connection']:
"""
value = None

not_implemented_get_conn_value = False
# TODO: after removal of ``get_conn_uri`` we should not catch NotImplementedError here
with suppress(NotImplementedError):
try:
value = self.get_conn_value(conn_id=conn_id)

if not value:
with suppress(NotImplementedError):
except NotImplementedError:
not_implemented_get_conn_value = True
warnings.warn(
"Method `get_conn_uri` is deprecated. Please use `get_conn_value`.",
PendingDeprecationWarning,
stacklevel=2,
)

if not_implemented_get_conn_value:
try:
value = self.get_conn_uri(conn_id=conn_id)
warnings.warn(
"Method `get_conn_uri` is deprecated. Please use `get_conn_value`.",
PendingDeprecationWarning,
stacklevel=2,
except NotImplementedError:
raise NotImplementedError(
f"Secrets backend {self.__class__.__name__} neither implements "
"`get_conn_value` nor `get_conn_uri`. Method `get_conn_uri` is "
"deprecated and will be removed in a future release. Please implement `get_conn_value`."
)

if value:
Expand Down