astronomer / dag-factory

Dynamically generate Apache Airflow DAGs from YAML configuration files
Apache License 2.0
1.21k stars 180 forks source link

template_searchpath seems to not work in YAML file #95

Open cordon-thiago opened 3 years ago

cordon-thiago commented 3 years ago

Hi, first of all, nice job on this project.

I'm trying to configure a DAG pointing to scripts in a path different from the DAG's path so, I'm setting the template_searchpath in YAML config to point to this location but I'm receiving the error: jinja2.exceptions.TemplateNotFound: /opt/airflow/scripts/query.sql so I guess the template_searchpath is not working. If I place the query.sql in the DAG's path, it works.

Here is my YAML

default:
  default_args:
    owner: "dag-factory"
    start_date: 2 days
    retries: 1
    retry_delay_sec: 300
  concurrency: 1
  max_active_runs: 1
  dagrun_timeout_sec: 600
  default_view: "graph"
  orientation: "LR"
  schedule_interval: "0 1 * * *"
  catchup: False
  tags: ['dag-factory']
  template_searchpath: ["/opt/airflow/scripts"]

example_sql_exec_query:
  description: "DAG to run SQL query"
  tasks:
    begin:
      operator: airflow.operators.dummy_operator.DummyOperator
    exec_sql:
      operator: airflow.operators.postgres_operator.PostgresOperator
      postgres_conn_id: "postgres"
      sql: /opt/airflow/scripts/query.sql # it doesn't work.
      params: {"columns": "dag_id, owners", "table": "public.dag", "limit": 10}
      dependencies: [begin]

Does anybody with the same issue?

brucemen711 commented 3 years ago

It appears that this setting isn't included on dag-factory.

brucemen711 commented 3 years ago

@ajbosco is there any reason for this, maybe we need add this param ? I also think that dag params name should be in config too, so user can config a whitelist for dynamic change depend on airflow version.

ajbosco commented 3 years ago

@brucemen711 That sounds reasonable to me. Want to submit a PR with the change?

brucemen711 commented 3 years ago

Yes, i'd love to. I'll create a PR for this first then do a design for dynamic config.