uranusjr commented on a change in pull request #16768:
URL: https://github.com/apache/airflow/pull/16768#discussion_r663411782



##########
File path: airflow/models/taskinstance.py
##########
@@ -1495,8 +1495,7 @@ def handle_failure(
             except Exception:
                 self.log.exception('Failed to send email to: %s', task.email)
 
-        if not test_mode:
-            session.merge(self)
+        session.merge(self)

Review comment:
       Is this related?

##########
File path: tests/dag_processing/test_processor.py
##########
@@ -643,6 +643,30 @@ def test_execute_on_failure_callbacks(self, 
mock_ti_handle_failure):
                 test_mode=conf.getboolean('core', 'unit_test_mode'),
             )
 
+    def test_failure_callbacks_should_not_drop_hostname(self):
+        dagbag = DagBag(dag_folder="/dev/null", include_examples=True, 
read_dags_from_db=False)
+        dag_file_processor = DagFileProcessor(dag_ids=[], log=mock.MagicMock())
+        with create_session() as session:
+            session.query(TaskInstance).delete()
+            dag = dagbag.get_dag('example_branch_operator')
+            task = dag.get_task(task_id='run_this_first')
+
+            ti = TaskInstance(task, DEFAULT_DATE, State.RUNNING)
+            ti.hostname = "test_hostname"
+
+            session.add(ti)
+            session.commit()

Review comment:
       Split this block into two `create_session()`s instead of using 
`commit()`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to