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/11/01 20:17:17 UTC
[GitHub] ashb closed pull request #2190: [AIRFLOW-1027] Fix error in task
details when using functools.partial in PythonOperator
ashb closed pull request #2190: [AIRFLOW-1027] Fix error in task details when using functools.partial in PythonOperator
URL: https://github.com/apache/incubator-airflow/pull/2190
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 15735b4b79..f39c388685 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -19,7 +19,7 @@
import os
import pkg_resources
import socket
-from functools import wraps
+from functools import wraps, partial
from datetime import datetime, timedelta
import dateutil.parser
import copy
@@ -220,7 +220,7 @@ def wrapped_markdown(s):
'doc_yaml': lambda x: render(x, lexers.YamlLexer),
'doc_md': wrapped_markdown,
'python_callable': lambda x: render(
- inspect.getsource(x), lexers.PythonLexer),
+ inspect.getsource(x if not isinstance(x, partial) else x.func), lexers.PythonLexer),
}
diff --git a/tests/core.py b/tests/core.py
index 848553af3e..c1fcfa58e0 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -1652,6 +1652,13 @@ def test_fetch_task_instance(self):
response = self.app.get(url)
self.assertIn("run_this_last", response.data.decode('utf-8'))
+ def test_dag_view_task_with_python_operator_using_partial(self):
+ response = self.app.get(
+ '/admin/airflow/task?'
+ 'task_id=test_dagrun_functool_partial&dag_id=test_issue_AIRFLOW_1027_dag&'
+ 'execution_date={}'.format(DEFAULT_DATE_DS))
+ self.assertEquals(response.status_code, 200)
+
def tearDown(self):
configuration.conf.set("webserver", "expose_config", "False")
self.dag_bash.clear(start_date=DEFAULT_DATE, end_date=datetime.now())
diff --git a/tests/dags/test_issue_AIRFLOW_1027.py b/tests/dags/test_issue_AIRFLOW_1027.py
new file mode 100644
index 0000000000..0e14cfb759
--- /dev/null
+++ b/tests/dags/test_issue_AIRFLOW_1027.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed 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.
+
+
+"""
+DAG designed to test a PythonOperator that calls a functool.partial
+"""
+import functools
+
+from datetime import datetime
+
+from airflow.models import DAG
+from airflow.operators.python_operator import PythonOperator
+
+DEFAULT_DATE = datetime(2016, 1, 1)
+default_args = dict(
+ start_date=DEFAULT_DATE,
+ owner='airflow')
+
+
+def func_with_two_args(arg_1, arg_2):
+ pass
+
+
+partial_func = functools.partial(func_with_two_args, arg_1=1)
+
+
+dag = DAG(dag_id='test_issue_AIRFLOW_1027_dag', default_args=default_args)
+
+dag_task1 = PythonOperator(
+ task_id='test_dagrun_functool_partial',
+ dag=dag,
+ python_callable=partial_func)
----------------------------------------------------------------
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