Skip to content

Commit 217d6f3

Browse files
authored
Fix SDK to read default_email_on_failure and default_email_on_retry from config (#59912)
* Added variable to fetch email on retry/failure values from conf * prek formatting * prek formatting
1 parent 98d5976 commit 217d6f3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

task-sdk/src/airflow/sdk/bases/operator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from airflow.sdk import TriggerRule, timezone
3939
from airflow.sdk._shared.secrets_masker import redact
4040
from airflow.sdk.definitions._internal.abstractoperator import (
41+
DEFAULT_EMAIL_ON_FAILURE,
42+
DEFAULT_EMAIL_ON_RETRY,
4143
DEFAULT_IGNORE_FIRST_DEPENDS_ON_PAST,
4244
DEFAULT_OWNER,
4345
DEFAULT_POOL_NAME,
@@ -219,8 +221,8 @@ def partial(**kwargs):
219221
OPERATOR_DEFAULTS: dict[str, Any] = {
220222
"allow_nested_operators": True,
221223
"depends_on_past": False,
222-
"email_on_failure": True,
223-
"email_on_retry": True,
224+
"email_on_failure": DEFAULT_EMAIL_ON_FAILURE,
225+
"email_on_retry": DEFAULT_EMAIL_ON_RETRY,
224226
"execution_timeout": DEFAULT_TASK_EXECUTION_TIMEOUT,
225227
# "executor": DEFAULT_EXECUTOR,
226228
"executor_config": {},
@@ -826,8 +828,8 @@ def say_hello_world(**context):
826828
task_id: str
827829
owner: str = DEFAULT_OWNER
828830
email: str | Sequence[str] | None = None
829-
email_on_retry: bool = True
830-
email_on_failure: bool = True
831+
email_on_retry: bool = DEFAULT_EMAIL_ON_RETRY
832+
email_on_failure: bool = DEFAULT_EMAIL_ON_FAILURE
831833
retries: int | None = DEFAULT_RETRIES
832834
retry_delay: timedelta = DEFAULT_RETRY_DELAY
833835
retry_exponential_backoff: float = 0
@@ -984,8 +986,8 @@ def __init__(
984986
task_id: str,
985987
owner: str = DEFAULT_OWNER,
986988
email: str | Sequence[str] | None = None,
987-
email_on_retry: bool = True,
988-
email_on_failure: bool = True,
989+
email_on_retry: bool = DEFAULT_EMAIL_ON_RETRY,
990+
email_on_failure: bool = DEFAULT_EMAIL_ON_FAILURE,
989991
retries: int | None = DEFAULT_RETRIES,
990992
retry_delay: timedelta | float = DEFAULT_RETRY_DELAY,
991993
retry_exponential_backoff: float = 0,

task-sdk/src/airflow/sdk/definitions/_internal/abstractoperator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
DEFAULT_TASK_EXECUTION_TIMEOUT: datetime.timedelta | None = conf.gettimedelta(
7777
"core", "default_task_execution_timeout"
7878
)
79-
79+
DEFAULT_EMAIL_ON_FAILURE: bool = conf.getboolean("email", "default_email_on_failure", fallback=True)
80+
DEFAULT_EMAIL_ON_RETRY: bool = conf.getboolean("email", "default_email_on_retry", fallback=True)
8081
log = logging.getLogger(__name__)
8182

8283

0 commit comments

Comments
 (0)