kaxil closed pull request #4073: [AIRFLOW-3238] Fix 
models.DAG.deactivate_unknown_dags
URL: https://github.com/apache/incubator-airflow/pull/4073
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/models.py b/airflow/models.py
index 40c466c9d9..8071585323 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -4358,6 +4358,7 @@ def deactivate_unknown_dags(active_dag_ids, session=None):
                 DagModel).filter(~DagModel.dag_id.in_(active_dag_ids)).all():
             dag.is_active = False
             session.merge(dag)
+        session.commit()
 
     @staticmethod
     @provide_session
diff --git a/tests/models.py b/tests/models.py
index f2d36a263b..e7ca343ca1 100644
--- a/tests/models.py
+++ b/tests/models.py
@@ -1691,6 +1691,31 @@ def test_kill_zombies(self, mock_ti):
                                    configuration.getboolean('core', 
'unit_test_mode'),
                                    ANY)
 
+    def test_deactivate_unknown_dags(self):
+        """
+        Test that dag_ids not passed into deactivate_unknown_dags
+        are deactivated when function is invoked
+        """
+        dagbag = models.DagBag(include_examples=True)
+        expected_active_dags = dagbag.dags.keys()
+
+        session = settings.Session
+        session.add(DagModel(dag_id='test_deactivate_unknown_dags', 
is_active=True))
+        session.commit()
+
+        models.DAG.deactivate_unknown_dags(expected_active_dags)
+
+        for dag in session.query(DagModel).all():
+            if dag.dag_id in expected_active_dags:
+                self.assertTrue(dag.is_active)
+            else:
+                self.assertEquals(dag.dag_id, 'test_deactivate_unknown_dags')
+                self.assertFalse(dag.is_active)
+
+        # clean up
+        session.query(DagModel).filter(DagModel.dag_id == 
'test_deactivate_unknown_dags').delete()
+        session.commit()
+
 
 class TaskInstanceTest(unittest.TestCase):
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to