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 2022/06/15 15:53:37 UTC

[GitHub] [airflow] eladkal commented on issue #23129: BigQueryInsertJobOperator fails when there are templated variables in default args

eladkal commented on issue #23129:
URL: https://github.com/apache/airflow/issues/23129#issuecomment-1156646825

   > I think it would be possible to answer all those questions but I think currently the answer is " default_args are not processed by JINJA"
   
   I don't think this is true. `default_args` just "unpack" at operator contractor - this is done while parsing the dag not during run time.
   
   I used this code:
   ```
   
   import pendulum
   
   from airflow import DAG
   from airflow.operators.bash import BashOperator
   
   default_args = {
       "bash_command": "echo {{ ds }}"
   }
   
   with DAG(
       dag_id='testing_default_args',
       schedule_interval='0 0 * * *',
       start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
       catchup=False,
       default_args=default_args
   ) as dag:
   
       run_this = BashOperator(
           task_id='run_after_loop',
       )
   ```
   
   
   and it worked fine:
   ![Screen Shot 2022-06-15 at 18 50 07](https://user-images.githubusercontent.com/45845474/173870949-be123d08-cddb-4a59-9b57-8ef3ca3053cf.png)
   
   
   
   @leahecole in your code example you try to template `region`, `project_id` in BigQueryInsertJobOperator but both are not templated fields:
   
   https://github.com/apache/airflow/blob/8e0bddaea69db4d175f03fa99951f6d82acee84d/airflow/providers/google/cloud/operators/bigquery.py#L2070-L2074
   
   
   Can you please try it with:
   
   ```
   class MyBigQueryInsertJobOperator(BigQueryInsertJobOperator):
       template_fields: Sequence[str] = (
           "region",
           "project_id",
       ) + BigQueryInsertJobOperator.template_fields
   
   ```
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org