|
34 | 34 | from uuid import uuid4
|
35 | 35 |
|
36 | 36 | import pendulum
|
| 37 | +import psutil |
37 | 38 | import pytest
|
38 | 39 | import time_machine
|
39 | 40 | from sqlalchemy import select
|
|
83 | 84 | from airflow.sensors.base import BaseSensorOperator
|
84 | 85 | from airflow.sensors.python import PythonSensor
|
85 | 86 | from airflow.serialization.serialized_objects import SerializedBaseOperator, SerializedDAG
|
86 |
| -from airflow.settings import TIMEZONE, TracebackSessionForTests |
| 87 | +from airflow.settings import TIMEZONE, TracebackSessionForTests, reconfigure_orm |
87 | 88 | from airflow.stats import Stats
|
88 | 89 | from airflow.ti_deps.dep_context import DepContext
|
89 | 90 | from airflow.ti_deps.dependencies_deps import REQUEUEABLE_DEPS, RUNNING_DEPS
|
@@ -3587,6 +3588,40 @@ def test_handle_failure(self, create_dummy_dag, session=None):
|
3587 | 3588 | assert "task_instance" in context_arg_3
|
3588 | 3589 | mock_on_retry_3.assert_not_called()
|
3589 | 3590 |
|
| 3591 | + @provide_session |
| 3592 | + def test_handle_failure_does_not_push_stale_dagrun_model(self, dag_maker, create_dummy_dag, session=None): |
| 3593 | + session = settings.Session() |
| 3594 | + with dag_maker(): |
| 3595 | + |
| 3596 | + def method(): ... |
| 3597 | + |
| 3598 | + task = PythonOperator(task_id="mytask", python_callable=method) |
| 3599 | + dr = dag_maker.create_dagrun() |
| 3600 | + ti = dr.get_task_instance(task.task_id) |
| 3601 | + ti.state = State.RUNNING |
| 3602 | + |
| 3603 | + assert dr.state == DagRunState.RUNNING |
| 3604 | + |
| 3605 | + session.merge(ti) |
| 3606 | + session.flush() |
| 3607 | + session.commit() |
| 3608 | + |
| 3609 | + pid = os.fork() |
| 3610 | + if pid: |
| 3611 | + process = psutil.Process(pid) |
| 3612 | + dr.state = DagRunState.SUCCESS |
| 3613 | + session.merge(dr) |
| 3614 | + session.flush() |
| 3615 | + session.commit() |
| 3616 | + process.wait(timeout=5) |
| 3617 | + else: |
| 3618 | + reconfigure_orm(disable_connection_pool=True) |
| 3619 | + ti.handle_failure("should not update related models") |
| 3620 | + os._exit(0) |
| 3621 | + |
| 3622 | + dr.refresh_from_db() |
| 3623 | + assert dr.state == DagRunState.SUCCESS |
| 3624 | + |
3590 | 3625 | @pytest.mark.skip_if_database_isolation_mode # Does not work in db isolation mode
|
3591 | 3626 | def test_handle_failure_updates_queued_task_updates_state(self, dag_maker):
|
3592 | 3627 | session = settings.Session()
|
|
0 commit comments