From 63c12503a7bef6cc3a3e2626893c8fbbb5e9a2f2 Mon Sep 17 00:00:00 2001 From: jason810496 Date: Wed, 4 Dec 2024 15:04:06 +0800 Subject: [PATCH] Remove Provider Deprecations in SendGrid --- .../airflow/providers/sendgrid/CHANGELOG.rst | 12 ++++++++++++ .../providers/sendgrid/utils/emailer.py | 18 ++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/providers/src/airflow/providers/sendgrid/CHANGELOG.rst b/providers/src/airflow/providers/sendgrid/CHANGELOG.rst index 5928b42144aae..92d038674c9d8 100644 --- a/providers/src/airflow/providers/sendgrid/CHANGELOG.rst +++ b/providers/src/airflow/providers/sendgrid/CHANGELOG.rst @@ -27,6 +27,18 @@ Changelog --------- +main +..... + +.. warning:: + All deprecated classes, parameters and features have been removed from the SendGrid provider package. + The following breaking changes were introduced: + + * Utils + + * Removed Fetching SendGrid credentials from environment variables. Use ``Connection`` to set credentials instead. + + 3.6.0 ..... diff --git a/providers/src/airflow/providers/sendgrid/utils/emailer.py b/providers/src/airflow/providers/sendgrid/utils/emailer.py index c096246d25076..f22a080deba78 100644 --- a/providers/src/airflow/providers/sendgrid/utils/emailer.py +++ b/providers/src/airflow/providers/sendgrid/utils/emailer.py @@ -23,7 +23,6 @@ import logging import mimetypes import os -import warnings from collections.abc import Iterable from typing import Union @@ -40,7 +39,6 @@ SandBoxMode, ) -from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning from airflow.hooks.base import BaseHook from airflow.utils.email import get_email_address_list @@ -126,20 +124,8 @@ def send_email( def _post_sendgrid_mail(mail_data: dict, conn_id: str = "sendgrid_default") -> None: - api_key = None - try: - conn = BaseHook.get_connection(conn_id) - api_key = conn.password - except AirflowException: - pass - if api_key is None: - warnings.warn( - "Fetching Sendgrid credentials from environment variables will be deprecated in a future " - "release. Please set credentials using a connection instead.", - AirflowProviderDeprecationWarning, - stacklevel=2, - ) - api_key = os.environ.get("SENDGRID_API_KEY") + conn = BaseHook.get_connection(conn_id) + api_key = conn.password sendgrid_client = sendgrid.SendGridAPIClient(api_key=api_key) response = sendgrid_client.client.mail.send.post(request_body=mail_data) # 2xx status code.