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 2019/01/05 07:18:27 UTC

[GitHub] shubhparekh closed pull request #4438: [AIRFLOW-3626] Fixed zipped Dag trigger

shubhparekh closed pull request #4438: [AIRFLOW-3626] Fixed zipped Dag trigger
URL: https://github.com/apache/incubator-airflow/pull/4438
 
 
   

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/__init__.py b/airflow/models/__init__.py
index b2561e2fdb..ee694b56b8 100755
--- a/airflow/models/__init__.py
+++ b/airflow/models/__init__.py
@@ -92,7 +92,7 @@
 
 from airflow.ti_deps.dep_context import DepContext, QUEUE_DEPS, RUN_DEPS
 from airflow.utils import timezone
-from airflow.utils.dag_processing import list_py_file_paths
+from airflow.utils.dag_processing import list_py_file_paths, correct_maybe_zipped_fileloc
 from airflow.utils.dates import cron_presets, date_range as utils_date_range
 from airflow.utils.db import provide_session
 from airflow.utils.decorators import apply_defaults
@@ -542,6 +542,7 @@ def collect_dags(
         stats = []
         FileLoadStat = namedtuple(
             'FileLoadStat', "file duration dag_num task_num dags")
+        dag_folder = correct_maybe_zipped_fileloc(dag_folder)
         for filepath in list_py_file_paths(dag_folder, include_examples):
             try:
                 ts = timezone.utcnow()
diff --git a/airflow/utils/dag_processing.py b/airflow/utils/dag_processing.py
index 6425f77745..a6747fd996 100644
--- a/airflow/utils/dag_processing.py
+++ b/airflow/utils/dag_processing.py
@@ -275,6 +275,20 @@ def get_dag(self, dag_id):
         return self.dag_id_to_simple_dag[dag_id]
 
 
+def correct_maybe_zipped_fileloc(fileloc):
+    """
+    If the path contains a folder with a .zip suffix, then
+    the folder is treated as a zip archive and path to zip is returned.
+    """
+
+    _, archive, filename = re.search(
+        r'((.*\.zip){})?(.*)'.format(re.escape(os.sep)), fileloc).groups()
+    if archive and zipfile.is_zipfile(archive):
+        return archive
+    else:
+        return fileloc
+
+
 def list_py_file_paths(directory, safe_mode=True,
                        include_examples=conf.getboolean('core', 'LOAD_EXAMPLES')):
     """


 

----------------------------------------------------------------
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