[GitHub] feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps records in Log Table when delete DAG & refine related tests

2018-12-06 Thread GitBox
feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps 
records in Log Table when delete DAG & refine related tests
URL: https://github.com/apache/incubator-airflow/pull/4287#discussion_r239715180
 
 

 ##
 File path: airflow/api/common/experimental/delete_dag.py
 ##
 @@ -41,6 +49,8 @@ def delete_dag(dag_id):
 # noinspection PyUnresolvedReferences,PyProtectedMember
 for m in models.Base._decl_class_registry.values():
 if hasattr(m, "dag_id"):
+if keep_records_in_log and m.__name__ == 'Log':
 
 Review comment:
   thanks for the explanation. make sense


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps records in Log Table when delete DAG & refine related tests

2018-12-06 Thread GitBox
feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps 
records in Log Table when delete DAG & refine related tests
URL: https://github.com/apache/incubator-airflow/pull/4287#discussion_r239559570
 
 

 ##
 File path: airflow/api/common/experimental/delete_dag.py
 ##
 @@ -41,6 +49,8 @@ def delete_dag(dag_id):
 # noinspection PyUnresolvedReferences,PyProtectedMember
 for m in models.Base._decl_class_registry.values():
 if hasattr(m, "dag_id"):
+if keep_records_in_log and m.__name__ == 'Log':
 
 Review comment:
   does it work with the log is in remote(like s3)? And will it have two 
different behaviour(api vs webserver) when deleting the log?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps records in Log Table when delete DAG & refine related tests

2018-12-06 Thread GitBox
feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps 
records in Log Table when delete DAG & refine related tests
URL: https://github.com/apache/incubator-airflow/pull/4287#discussion_r239559208
 
 

 ##
 File path: tests/api/common/experimental/test_delete_dag.py
 ##
 @@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from airflow import models
+from airflow import settings
+from airflow.api.common.experimental.delete_dag import delete_dag
+from airflow.exceptions import DagNotFound, DagFileExists
+from airflow.operators.dummy_operator import DummyOperator
+from airflow.utils.dates import days_ago
+from airflow.utils.state import State
+
+DM = models.DagModel
+DS = models.DagStat
+DR = models.DagRun
+TI = models.TaskInstance
+LOG = models.Log
+
+
+class TestDeleteDAG_catch_error(unittest.TestCase):
 
 Review comment:
   please use capwords for class 
name(https://www.python.org/dev/peps/pep-0008/#class-names).


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps records in Log Table when delete DAG & refine related tests

2018-12-06 Thread GitBox
feng-tao commented on a change in pull request #4287: [AIRFLOW-3479] Keeps 
records in Log Table when delete DAG & refine related tests
URL: https://github.com/apache/incubator-airflow/pull/4287#discussion_r239559313
 
 

 ##
 File path: tests/api/common/experimental/test_delete_dag.py
 ##
 @@ -0,0 +1,141 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+from airflow import models
+from airflow import settings
+from airflow.api.common.experimental.delete_dag import delete_dag
+from airflow.exceptions import DagNotFound, DagFileExists
+from airflow.operators.dummy_operator import DummyOperator
+from airflow.utils.dates import days_ago
+from airflow.utils.state import State
+
+DM = models.DagModel
+DS = models.DagStat
+DR = models.DagRun
+TI = models.TaskInstance
+LOG = models.Log
+
+
+class TestDeleteDAG_catch_error(unittest.TestCase):
+
+def setUp(self):
+self.session = settings.Session()
+self.dagbag = models.DagBag(include_examples=True)
+self.dag_id = 'example_bash_operator'
+self.dag = self.dagbag.dags[self.dag_id]
+
+def tearDown(self):
+self.dag.clear()
+self.session.close()
+
+def test_delete_dag_non_existent_dag(self):
+with self.assertRaises(DagNotFound):
+delete_dag("non-existent DAG")
+
+def test_delete_dag_dag_still_in_dagbag(self):
+models_to_check = ['DagModel', 'DagStat', 'DagRun', 'TaskInstance']
+record_counts = {}
+
+for model_name in models_to_check:
+m = getattr(models, model_name)
+record_counts[model_name] = self.session.query(m).filter(m.dag_id 
== self.dag_id).count()
+
+with self.assertRaises(DagFileExists):
+delete_dag(self.dag_id)
+
+# No change should happen in DB
+for model_name in models_to_check:
+m = getattr(models, model_name)
+self.assertEqual(
+self.session.query(m).filter(
+m.dag_id == self.dag_id
+).count(),
+record_counts[model_name]
+)
+
+
+class TestDeleteDAG_successful_delete(unittest.TestCase):
 
 Review comment:
   same


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:
us...@infra.apache.org


With regards,
Apache Git Services