soooojinlee commented on code in PR #60999:
URL: https://github.com/apache/airflow/pull/60999#discussion_r2730256251
##########
task-sdk/src/airflow/sdk/definitions/_internal/templater.py:
##########
@@ -57,6 +64,264 @@ def resolve(self, context: Context) -> Any:
log = logging.getLogger(__name__)
+class ZipAwareFileSystemLoader(jinja2.FileSystemLoader):
+ """
+ A Jinja2 template loader that extends FileSystemLoader to support loading
templates from within zip archives.
+
+ This loader handles the case where DAGs are packaged as zip files.
+
+ This loader handles the case where DAGs are packaged as zip files. When a
+ searchpath contains a zip file path (e.g., "/path/to/dags.zip" or
+ "/path/to/dags.zip/subdir"), templates inside the zip can be loaded
transparently.
+
+ For regular filesystem paths, it delegates to the parent FileSystemLoader
+ for optimal performance.
+
+ This addresses Issue #59310 where template files in zipped DAG packages
+ could not be resolved by the standard FileSystemLoader.
+
+ :param searchpath: A list of paths to search for templates. Paths can be:
+ - Regular filesystem directories
+ - Paths to zip files (will search inside the zip root)
+ - Paths inside zip files (e.g., "archive.zip/subdir")
+ :param encoding: The encoding to use when reading template files.
+ :param followlinks: Whether to follow symbolic links (for regular
directories).
+
+ Example usage::
+
+ loader = ZipAwareFileSystemLoader(["/path/to/dags.zip",
"/path/to/templates"])
+ env = jinja2.Environment(loader=loader)
+ template = env.get_template("query.sql")
+
+ See: https://github.com/apache/airflow/issues/59310
+ """
Review Comment:
I've addressed the review feedback [here
](https://github.com/apache/airflow/pull/60999/changes/06e5ec8269d3865be8c5759decd62b1d536253a3)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]