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 2021/07/22 14:04:57 UTC

[GitHub] [airflow] jmaldon1 opened a new issue #17164: `params` not working with Python Decorator API. [jinja2.exceptions.UndefinedError: 'dict object' has no attribute]

jmaldon1 opened a new issue #17164:
URL: https://github.com/apache/airflow/issues/17164


   **Apache Airflow version**: v2.1.0
   
   
   **Kubernetes version (if you are using kubernetes)** (use `kubectl version`):
   
   **Environment**:
   
   - **Cloud provider or hardware configuration**:
   - **OS** (e.g. from /etc/os-release): Macos
   - **Kernel** (e.g. `uname -a`):
   - **Install tools**:
   - **Others**:
   
   **What happened**:
   
   ```python
   @dag(dag_id=dag_id,
        user_defined_macros={
           "target_id_column": target_id_column
        })
   def dynamic_dag():
   
       def get_max_id_from_target_table(conn_id: str, max_id_sql: str, **kwargs) -> int:
           print(max_id_sql)  # This should be templated
   
       
       source_conn_id = "some_conn_id"
       max_id_sql = """
           select max({{ target_id_column }}) as max_delta
           from {{ params.target_table }} WITH (NOLOCK);
       """
       target_table = "table_name"
       max_id_from_target_results = get_max_id_from_target_table(source_conn_id,
                                                                   max_id_sql,
                                                                   params={
                                                                       "target_table": target_table
                                                                   })
   ```
   
   Error:
   ```
   jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'target_table'
   ```
   
   <!-- (please include exact error messages if you can) -->
   
   **What you expected to happen**:
   
   Jinja should be taking the `target_table` variable from the `params` arg.
   
   <!-- What do you think went wrong? -->
   
   **How to reproduce it**:
   
   The code above is a minimal reproducible error
   <!---
   
   As minimally and precisely as possible. Keep in mind we do not have access to your cluster or dags.
   
   If you are using kubernetes, please attempt to recreate the issue using minikube or kind.
   
   ## Install minikube/kind
   
   - Minikube https://minikube.sigs.k8s.io/docs/start/
   - Kind https://kind.sigs.k8s.io/docs/user/quick-start/
   
   If this is a UI bug, please provide a screenshot of the bug or a link to a youtube video of the bug in action
   
   You can include images using the .md style of
   ![alt text](http://url/to/img.png)
   
   To record a screencast, mac users can use QuickTime and then create an unlisted youtube video with the resulting .mov file.
   
   --->
   
   
   **Anything else we need to know**:
   
   `user_defined_macros` seems to work just fine.
   
   <!--
   
   How often does this problem occur? Once? Every time etc?
   
   Any relevant logs to include? Put them here in side a detail tag:
   <details><summary>x.log</summary> lots of stuff </details>
   
   -->
   


-- 
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



[GitHub] [airflow] jmaldon1 commented on issue #17164: `params` not working with Python Task Decorator. [jinja2.exceptions.UndefinedError: 'dict object' has no attribute]

Posted by GitBox <gi...@apache.org>.
jmaldon1 commented on issue #17164:
URL: https://github.com/apache/airflow/issues/17164#issuecomment-884961413


   SOLUTION:
   params actually go into the `@task` decorator.
   
   ```python
   @task(params={
           "target_table": target_table
           })
   ```


-- 
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



[GitHub] [airflow] jmaldon1 closed issue #17164: `params` not working with Python Task Decorator. [jinja2.exceptions.UndefinedError: 'dict object' has no attribute]

Posted by GitBox <gi...@apache.org>.
jmaldon1 closed issue #17164:
URL: https://github.com/apache/airflow/issues/17164


   


-- 
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