You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by je...@apache.org on 2022/02/16 15:54:41 UTC

[airflow] branch main updated: Don't check if `py` DAG files are zipped during parsing (#21538)

This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new d87762b  Don't check if `py` DAG files are zipped during parsing (#21538)
d87762b is described below

commit d87762b3cc8170b78b0dac5c1ff932df913346fe
Author: Sungpeo Kook <ju...@gmail.com>
AuthorDate: Thu Feb 17 00:53:45 2022 +0900

    Don't check if `py` DAG files are zipped during parsing (#21538)
---
 UPDATING.md              | 4 ++++
 airflow/models/dagbag.py | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/UPDATING.md b/UPDATING.md
index 175f9dd..8b7267f 100644
--- a/UPDATING.md
+++ b/UPDATING.md
@@ -80,6 +80,10 @@ https://developers.google.com/style/inclusive-documentation
 
 -->
 
+### Zip files in the DAGs folder can no longer have a `.py` extension
+
+It was previously possible to have any extension for zip files in the DAGs folder. Now `.py` files are going to be loaded as modules without checking whether it is a zip file, as it leads to less IO. If a `.py` file in the DAGs folder is a zip compressed file, parsing it will fail with an exception.
+
 ### You have to use `postgresql://` instead of `postgres://` in `sql_alchemy_conn` for SQLAlchemy 1.4.0+
 
 When you use SQLAlchemy 1.4.0+, you need ot use `postgresql://` as the database in the `sql_alchemy_conn`.
diff --git a/airflow/models/dagbag.py b/airflow/models/dagbag.py
index 0136d7f..4908cfd 100644
--- a/airflow/models/dagbag.py
+++ b/airflow/models/dagbag.py
@@ -284,7 +284,7 @@ class DagBag(LoggingMixin):
             self.log.exception(e)
             return []
 
-        if not zipfile.is_zipfile(filepath):
+        if filepath.endswith(".py") or not zipfile.is_zipfile(filepath):
             mods = self._load_modules_from_file(filepath, safe_mode)
         else:
             mods = self._load_modules_from_zip(filepath, safe_mode)