You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/09/11 22:01:37 UTC

[GitHub] r39132 closed pull request #2055: [AIRFLOW-417] Show useful error message for missing DAG in URL

r39132 closed pull request #2055: [AIRFLOW-417] Show useful error message for missing DAG in URL
URL: https://github.com/apache/incubator-airflow/pull/2055
 
 
   

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/www/views.py b/airflow/www/views.py
index 1e9d49dfeb..073bfcaa59 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -1154,6 +1154,13 @@ def tree(self):
         dag_id = request.args.get('dag_id')
         blur = conf.getboolean('webserver', 'demo_mode')
         dag = dagbag.get_dag(dag_id)
+        if not dag:
+            flash(
+                "DAG [{}] doesn't seem to exist"
+                " at the moment".format(dag_id),
+                "error")
+            return redirect('/admin/')
+
         root = request.args.get('root')
         if root:
             dag = dag.sub_dag(
diff --git a/tests/core.py b/tests/core.py
index a4757a70a7..3cd220ba66 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -1787,6 +1787,19 @@ def test_fetch_task_instance(self):
         response = self.app.get(url)
         self.assertIn("run_this_last", response.data.decode('utf-8'))
 
+    def test_missing_dag_request(self):
+        response = self.app.get("/admin/airflow/graph?dag_id=missing_dag", follow_redirects=True)
+        # verify that user is redirected to the index page with an error message
+        assert "DAGs" in response.data.decode('utf-8')
+        assert "example_bash_operator" in response.data.decode('utf-8')
+        assert "alert-danger" in response.data.decode('utf-8')
+
+        response = self.app.get("/admin/airflow/graph?dag_id=example_bash_operator", follow_redirects=True)
+        # verify that the page for a valid DAG is rendered correctly
+        assert "example_bash_operator" in response.data.decode('utf-8')
+        assert "Graph View" in response.data.decode('utf-8')
+
+
     def tearDown(self):
         configuration.conf.set("webserver", "expose_config", "False")
         self.dag_bash.clear(start_date=DEFAULT_DATE, end_date=datetime.now())


 

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


With regards,
Apache Git Services