Skip to content

Commit

Permalink
Use AirflowProviderDeprecationWarning in providers (#30975)
Browse files Browse the repository at this point in the history
* Use `AirflowProviderDeprecationWarning` in providers
Now that Providers minimum Airflow version is 2.4.0 we can replace `DeprecationWarning` with `AirflowProviderDeprecationWarning`
  • Loading branch information
eladkal committed May 3, 2023
1 parent eb7b98d commit 0a30706
Show file tree
Hide file tree
Showing 91 changed files with 362 additions and 285 deletions.
4 changes: 2 additions & 2 deletions airflow/providers/amazon/aws/hooks/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from boto3.s3.transfer import S3Transfer, TransferConfig
from botocore.exceptions import ClientError

from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.amazon.aws.exceptions import S3HookUriParseFailure
from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
from airflow.providers.amazon.aws.utils.tags import format_tags
Expand Down Expand Up @@ -74,7 +74,7 @@ def wrapper(*args, **kwargs) -> T:
"s3 conn_type, and the associated schema field, is deprecated."
" Please use aws conn_type instead, and specify `bucket_name`"
" in `service_config.s3` within `extras`.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
bound_args.arguments["bucket_name"] = self.conn_config.schema
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/amazon/aws/operators/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from typing import TYPE_CHECKING, Any, Sequence

from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.amazon.aws.hooks.batch_client import BatchClientHook
from airflow.providers.amazon.aws.links.batch import (
Expand Down Expand Up @@ -163,7 +163,7 @@ def __init__(
self.container_overrides = overrides
warnings.warn(
"Parameter `overrides` is deprecated, Please use `container_overrides` instead.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)

Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/amazon/aws/operators/eks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from botocore.exceptions import ClientError, WaiterError

from airflow import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.amazon.aws.hooks.eks import EksHook

Expand Down Expand Up @@ -691,7 +691,7 @@ def __init__(
"Currently the default for this parameter is `False` but in a future release the default "
"will be changed to `True`. To ensure pods are not deleted in the future you will need to "
"set `is_delete_operator_pod=False` explicitly.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
is_delete_operator_pod = False
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/amazon/aws/operators/emr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import TYPE_CHECKING, Any, Sequence
from uuid import uuid4

from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.amazon.aws.hooks.emr import EmrContainerHook, EmrHook, EmrServerlessHook
from airflow.providers.amazon.aws.links.emr import EmrClusterLink
Expand Down Expand Up @@ -486,7 +486,7 @@ def __init__(
warnings.warn(
f"Parameter `{self.__class__.__name__}.max_tries` is deprecated and will be removed "
"in a future release. Please use method `max_polling_attempts` instead.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
if max_polling_attempts and max_polling_attempts != max_tries:
Expand Down
8 changes: 4 additions & 4 deletions airflow/providers/amazon/aws/operators/sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from botocore.exceptions import ClientError

from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
from airflow.providers.amazon.aws.hooks.sagemaker import SageMakerHook
Expand Down Expand Up @@ -201,7 +201,7 @@ def __init__(
warnings.warn(
"Action 'increment' on job name conflict has been deprecated for performance reasons."
"The alternative to 'fail' is now 'timestamp'.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
self.action_if_job_exists = action_if_job_exists
Expand Down Expand Up @@ -486,7 +486,7 @@ def __init__(
warnings.warn(
"Action 'increment' on job name conflict has been deprecated for performance reasons."
"The alternative to 'fail' is now 'timestamp'.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
self.action_if_job_exists = action_if_job_exists
Expand Down Expand Up @@ -718,7 +718,7 @@ def __init__(
warnings.warn(
"Action 'increment' on job name conflict has been deprecated for performance reasons."
"The alternative to 'fail' is now 'timestamp'.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
self.action_if_job_exists = action_if_job_exists
Expand Down
5 changes: 3 additions & 2 deletions airflow/providers/amazon/aws/secrets/secrets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from urllib.parse import unquote

from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.amazon.aws.utils import trim_none_values
from airflow.secrets import BaseSecretsBackend
from airflow.utils.log.logging_mixin import LoggingMixin
Expand Down Expand Up @@ -149,7 +150,7 @@ def __init__(
"The `full_url_mode` kwarg is deprecated. Going forward, the `SecretsManagerBackend`"
" will support both URL-encoded and JSON-encoded secrets at the same time. The encoding"
" of the secret will be determined automatically.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)

Expand All @@ -159,7 +160,7 @@ def __init__(
" migrating away from URL-encoding secret values for JSON secrets."
" To remove this warning, make sure your JSON secrets are *NOT* URL-encoded, and then"
" remove this kwarg from backend_kwargs.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
self.are_secret_values_urlencoded = kwargs.pop("are_secret_values_urlencoded", None)
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/amazon/aws/transfers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings
from typing import Sequence

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.models import BaseOperator
from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
from airflow.utils.types import NOTSET, ArgNotSet
Expand Down Expand Up @@ -60,7 +61,7 @@ def __init__(
) -> None:
super().__init__(**kwargs)
if not isinstance(aws_conn_id, ArgNotSet):
warnings.warn(_DEPRECATION_MSG, DeprecationWarning, stacklevel=3)
warnings.warn(_DEPRECATION_MSG, AirflowProviderDeprecationWarning, stacklevel=3)
self.source_aws_conn_id = aws_conn_id
else:
self.source_aws_conn_id = source_aws_conn_id
Expand Down
16 changes: 8 additions & 8 deletions airflow/providers/amazon/aws/utils/connection_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from botocore.config import Config

from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.amazon.aws.utils import trim_none_values
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.log.secrets_masker import mask_secret
Expand Down Expand Up @@ -168,7 +168,7 @@ def __post_init__(self, conn: Connection):
f"{self.conn_repr} has connection type 's3', "
"which has been replaced by connection type 'aws'. "
"Please update your connection to have `conn_type='aws'`.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
elif self.conn_type != "aws":
Expand All @@ -186,7 +186,7 @@ def __post_init__(self, conn: Connection):
warnings.warn(
"'session_kwargs' in extra config is deprecated and will be removed in a future releases. "
f"Please specify arguments passed to boto3 Session directly in {self.conn_repr} extra.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)

Expand Down Expand Up @@ -242,7 +242,7 @@ def __post_init__(self, conn: Connection):
warnings.warn(
f"Host {conn.host} specified in the connection is not used."
" Please, set it on extra['endpoint_url'] instead",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)

Expand All @@ -251,7 +251,7 @@ def __post_init__(self, conn: Connection):
warnings.warn(
"extra['host'] is deprecated and will be removed in a future release."
" Please set extra['endpoint_url'] instead",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
else:
Expand Down Expand Up @@ -385,7 +385,7 @@ def _get_assume_role_configs(
"Constructing 'role_arn' from extra['aws_account_id'] and extra['aws_iam_role'] is deprecated"
f" and will be removed in a future releases."
f" Please set 'role_arn' in {self.conn_repr} extra.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=3,
)
role_arn = f"arn:aws:iam::{aws_account_id}:role/{aws_iam_role}"
Expand Down Expand Up @@ -413,7 +413,7 @@ def _get_assume_role_configs(
warnings.warn(
"'external_id' in extra config is deprecated and will be removed in a future releases. "
f"Please set 'ExternalId' in 'assume_role_kwargs' in {self.conn_repr} extra.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=3,
)
assume_role_kwargs["ExternalId"] = external_id
Expand All @@ -436,7 +436,7 @@ def _parse_s3_config(
warnings.warn(
"Use local credentials file is never documented and well tested. "
"Obtain credentials by this way deprecated and will be removed in a future releases.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=4,
)

Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/apache/drill/operators/drill.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import warnings
from typing import Sequence

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator


Expand Down Expand Up @@ -49,6 +50,6 @@ def __init__(self, *, drill_conn_id: str = "drill_default", **kwargs) -> None:
warnings.warn(
"""This class is deprecated.
Please use `airflow.providers.common.sql.operators.sql.SQLExecuteQueryOperator`.""",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
3 changes: 2 additions & 1 deletion airflow/providers/apache/druid/operators/druid_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import warnings

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.common.sql.operators.sql import SQLCheckOperator


Expand All @@ -32,7 +33,7 @@ def __init__(self, druid_broker_conn_id: str = "druid_broker_default", **kwargs)
warnings.warn(
"""This class is deprecated.
Please use `airflow.providers.common.sql.operators.sql.SQLCheckOperator`.""",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
super().__init__(conn_id=druid_broker_conn_id, **kwargs)
6 changes: 4 additions & 2 deletions airflow/providers/apache/hive/hooks/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from tempfile import NamedTemporaryFile, TemporaryDirectory
from typing import Any, Iterable, Mapping

from airflow.exceptions import AirflowProviderDeprecationWarning

try:
import pandas
except ImportError as e:
Expand Down Expand Up @@ -529,7 +531,7 @@ def get_metastore_client(self) -> Any:
if "authMechanism" in conn.extra_dejson:
warnings.warn(
"The 'authMechanism' option is deprecated. Please use 'auth_mechanism'.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
conn.extra_dejson["auth_mechanism"] = conn.extra_dejson["authMechanism"]
Expand Down Expand Up @@ -844,7 +846,7 @@ def get_conn(self, schema: str | None = None) -> Any:
if "authMechanism" in db.extra_dejson:
warnings.warn(
"The 'authMechanism' option is deprecated. Please use 'auth_mechanism'.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
db.extra_dejson["auth_mechanism"] = db.extra_dejson["authMechanism"]
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/cncf/kubernetes/hooks/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from urllib3.exceptions import HTTPError

from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.hooks.base import BaseHook
from airflow.kubernetes.kube_client import _disable_verify_ssl, _enable_tcp_keepalive
from airflow.utils import yaml
Expand Down Expand Up @@ -351,7 +351,7 @@ def get_namespace(self) -> str | None:
"not defined in the connection so that it's clear whether user intends 'default' or "
"whether namespace is unset (which is required in order to apply precedence logic in "
"KubernetesPodOperator).",
DeprecationWarning,
AirflowProviderDeprecationWarning,
)
return "default"
return namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

import warnings

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.cncf.kubernetes.operators.pod import * # noqa

warnings.warn(
"This module is deprecated. Please use `airflow.providers.cncf.kubernetes.operators.pod` instead.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
10 changes: 7 additions & 3 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from urllib3.exceptions import HTTPError

from airflow.compat.functools import cached_property
from airflow.exceptions import AirflowException, AirflowSkipException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning, AirflowSkipException
from airflow.kubernetes import pod_generator
from airflow.kubernetes.pod_generator import PodGenerator
from airflow.kubernetes.secret import Secret
Expand Down Expand Up @@ -464,7 +464,11 @@ def hook(self) -> KubernetesHook:
return hook

def get_hook(self):
warnings.warn("get_hook is deprecated. Please use hook instead.", DeprecationWarning, stacklevel=2)
warnings.warn(
"get_hook is deprecated. Please use hook instead.",
AirflowProviderDeprecationWarning,
stacklevel=2,
)
return self.hook

@cached_property
Expand Down Expand Up @@ -577,7 +581,7 @@ def convert_config_file_to_dict(self):
"""Converts passed config_file to dict format."""
warnings.warn(
"This method is deprecated and will be removed in a future version.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
config_file = self.config_file if self.config_file else os.environ.get(KUBE_CONFIG_ENV_VAR)
Expand Down
3 changes: 2 additions & 1 deletion airflow/providers/cncf/kubernetes/triggers/kubernetes_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

import warnings

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.cncf.kubernetes.triggers.pod import * # noqa

warnings.warn(
"This module is deprecated. Please use `airflow.providers.cncf.kubernetes.triggers.pod` instead.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
stacklevel=2,
)
4 changes: 2 additions & 2 deletions airflow/providers/cncf/kubernetes/utils/pod_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from urllib3.exceptions import HTTPError as BaseHTTPError
from urllib3.response import HTTPResponse

from airflow.exceptions import AirflowException
from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.kubernetes.pod_generator import PodDefaults
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.timezone import utcnow
Expand Down Expand Up @@ -296,7 +296,7 @@ def follow_container_logs(self, pod: V1Pod, container_name: str) -> PodLoggingSt
warnings.warn(
"Method `follow_container_logs` is deprecated. Use `fetch_container_logs` instead"
"with option `follow=True`.",
DeprecationWarning,
AirflowProviderDeprecationWarning,
)
return self.fetch_container_logs(pod=pod, container_name=container_name, follow=True)

Expand Down

0 comments on commit 0a30706

Please sign in to comment.