Example #1
0
    def get_template_env(self) -> "jinja2.Environment":
        """Fetch a Jinja template environment from the DAG or instantiate empty environment if no DAG."""
        # This is imported locally since Jinja2 is heavy and we don't need it
        # for most of the functionalities. It is imported by get_template_env()
        # though, so we don't need to put this after the 'if dag' check.
        from airflow.templates import SandboxedEnvironment

        dag = self.get_dag()
        if dag:
            return dag.get_template_env()
        return SandboxedEnvironment(cache_size=0)
Example #2
0
 def get_template_env(self) -> jinja2.Environment:
     """Fetch a Jinja template environment from the DAG or instantiate empty environment if no DAG."""
     dag = self.get_dag()
     if dag:
         return dag.get_template_env()
     return SandboxedEnvironment(cache_size=0)