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

2018-12-07 Thread GitBox
XD-DENG 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_r239729799
 
 

 ##
 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 @feng-tao . May you help re-trigger the Travis test?
   
   Earlier most my test cases failed due to un-related tests. I believe it's 
some sort of transient errors.
   
   Thanks!


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] XD-DENG 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
XD-DENG 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_r239656929
 
 

 ##
 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:
   Hi @feng-tao , regarding your questions:
   
   1. `delete_dag()` function does not touch the log files (plain text files in 
`/log` folder) at all. It only deletes records of given dag_id in the tables in 
the backend database, including "dag", "task_instance", "dag_run", etc. 
(actually all tables in which `dag_id` is available). Earlier it also deletes 
the records in "log" table in the database, which may not be ideal (logs should 
not be touched by anyone other than Admin). This is what this PR is trying to 
solve.
   
   1. The behaviour (API vs webserver/UI) will be consistent: when a user 
deletes a DAG from UI, what happens under the hood is that the URL of the 
button will invoke the API endpoint with the _default_ parameter 
(`keep_records_in_log=True`). The only difference is that users can delete 
records in `log` table using API if they want (of course they need to 
explicitly specify `keep_records_in_log=False`).
   
   Please let me know if you need any other clarification. Thanks for reviewing!


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] XD-DENG 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
XD-DENG 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_r239655182
 
 

 ##
 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:
   Addressed. Thanks!


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] XD-DENG 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
XD-DENG 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_r239655165
 
 

 ##
 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:
   Thanks @feng-tao ! Have addressed this.


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