Give up on trying to recreate task_id logic#22794
Merged
uranusjr merged 2 commits intoapache:mainfrom Apr 7, 2022
Merged
Conversation
Member
|
A test for you diff --git a/tests/models/test_taskinstance.py b/tests/models/test_taskinstance.py
index 38be50b12..5311cb6ed 100644
--- a/tests/models/test_taskinstance.py
+++ b/tests/models/test_taskinstance.py
@@ -23,6 +23,7 @@ import pathlib
import signal
import sys
import urllib
+from contextlib import suppress
from tempfile import NamedTemporaryFile
from traceback import format_exception
from typing import List, Optional, Union, cast
@@ -55,6 +56,7 @@ from airflow.models import (
Variable,
XCom,
)
+from airflow.models.taskfail import TaskFail
from airflow.models.taskinstance import TaskInstance, load_error_file, set_error_file
from airflow.models.taskmap import TaskMap
from airflow.models.xcom import XCOM_RETURN_KEY
@@ -1358,6 +1360,39 @@ class TestTaskInstance:
assert 'template: test_email_alert_with_config' == title
assert 'template: test_email_alert_with_config' == body
+ @patch('airflow.models.taskinstance.send_email')
+ def test_failure_mapped_taskflow(self, mock_send_email, dag_maker, session):
+ with dag_maker(dag_id='test_failure_email', session=session) as dag:
+
+ @dag.task(email='to')
+ def test_email_alert(x):
+ raise RuntimeError("Fail please")
+
+ test_email_alert.expand(x=[1, 2, 3])
+ ti = sorted(
+ dag_maker.create_dagrun(execution_date=timezone.utcnow()).task_instances,
+ key=lambda ti: ti.map_index,
+ )[0]
+ assert ti.map_index == 0
+
+ with suppress(RuntimeError):
+ ti.run(session=session)
+
+ (email, title, body), _ = mock_send_email.call_args
+ assert email == 'to'
+ assert 'test_email_alert' in title
+ assert 'test_email_alert__1' not in title
+ assert 'map_index=0' in title
+ assert 'test_email_alert' in body
+ assert 'Try 1' in body
+
+ tf = (
+ session.query(TaskFail)
+ .filter_by(dag_id=ti.dag_id, task_id=ti.task_id, run_id=ti.run_id, map_index=ti.map_index)
+ .one()
+ )
+ assert tf, "TaskFail was recorded"
+
def test_set_duration(self):
task = DummyOperator(task_id='op', email='test@test.test')
ti = TI(task=task) |
Member
Author
|
Is there another PR adding the test or should I do it here? |
819e9aa to
da3540c
Compare
Member
|
Probably here for that test please. |
BaseOperator does way too much to modify task_id, let's give up on trying to recreate it and instead just forcefully overwrite.
da3540c to
3d5c33d
Compare
ashb
approved these changes
Apr 7, 2022
|
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BaseOperator does way too much to modify task_id, let's give up on trying to recreate it and instead just forcefully overwrite.
Inspired by @ashb’s hack