-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING_CHANGE: remove airflow.operators.email.EmailOperator in favo…
…r of SMTP provider operator (#46573) * BREAKING_CHANGE: remove airflow.operators.email.EmailOperator in favor of SMTP provider operator * Update newsfragments/46572.significant.rst Co-authored-by: Wei Lee <[email protected]> * fix static checks --------- Co-authored-by: Wei Lee <[email protected]>
- Loading branch information
1 parent
1644e03
commit 42db67b
Showing
7 changed files
with
33 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
|
||
from airflow.decorators import dag, task | ||
from airflow.models.baseoperator import BaseOperator | ||
from airflow.operators.email import EmailOperator | ||
from airflow.providers.standard.operators.bash import BashOperator | ||
|
||
if TYPE_CHECKING: | ||
from airflow.sdk.definitions.context import Context | ||
|
@@ -48,27 +48,24 @@ def execute(self, context: Context): | |
catchup=False, | ||
tags=["example"], | ||
) | ||
def example_dag_decorator(email: str = "[email protected]"): | ||
def example_dag_decorator(url: str = "http://httpbin.org/get"): | ||
""" | ||
DAG to send server IP to email. | ||
DAG to get IP address and echo it via BashOperator. | ||
:param email: Email to send IP to. Defaults to [email protected]. | ||
:param url: URL to get IP address from. Defaults to "http://httpbin.org/get". | ||
""" | ||
get_ip = GetRequestOperator(task_id="get_ip", url="http://httpbin.org/get") | ||
get_ip = GetRequestOperator(task_id="get_ip", url=url) | ||
|
||
@task(multiple_outputs=True) | ||
def prepare_email(raw_json: dict[str, Any]) -> dict[str, str]: | ||
def prepare_command(raw_json: dict[str, Any]) -> dict[str, str]: | ||
external_ip = raw_json["origin"] | ||
return { | ||
"subject": f"Server connected from {external_ip}", | ||
"body": f"Seems like today your server executing Airflow is connected from IP {external_ip}<br>", | ||
"command": f"echo 'Seems like today your server executing Airflow is connected from IP {external_ip}'", | ||
} | ||
|
||
email_info = prepare_email(get_ip.output) | ||
command_info = prepare_command(get_ip.output) | ||
|
||
EmailOperator( | ||
task_id="send_email", to=email, subject=email_info["subject"], html_content=email_info["body"] | ||
) | ||
BashOperator(task_id="echo_ip_info", bash_command=command_info["command"]) | ||
|
||
|
||
example_dag = example_dag_decorator() | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
In Airflow 3.0, ``airflow.operators.email.EmailOperator`` is removed. | ||
|
||
Instead, users can install ``smtp`` provider and import ``EmailOperator`` from the the module ``airflow.providers.smtp.operators.smtp``. | ||
|
||
* Types of change | ||
|
||
* [ ] Dag changes | ||
* [ ] Config changes | ||
* [ ] API changes | ||
* [ ] CLI changes | ||
* [ ] Behaviour changes | ||
* [ ] Plugin changes | ||
* [ ] Dependency changes | ||
* [x] Code interface changes | ||
|
||
* Migration rules needed | ||
|
||
* ruff | ||
|
||
* <RULE_ID> | ||
|
||
* [ ] ``airflow.operators.email`` → ``airflow.providers.smtp.operators.smtp.EmailOperator`` |
This file was deleted.
Oops, something went wrong.