[ 
https://issues.apache.org/jira/browse/AIRFLOW-4724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16890018#comment-16890018
 ] 

ASF GitHub Bot commented on AIRFLOW-4724:
-----------------------------------------

srivignessh commented on pull request #5637: [AIRFLOW-4724] Make params dict to 
be templated for operators
URL: https://github.com/apache/airflow/pull/5637
 
 
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [ ] My PR addresses the following [Airflow 
Jira](https://issues.apache.org/jira/browse/AIRFLOW-4724) issue and references 
them in the PR title. 
   ### Description
   
   - [ ] Here are some details about my PR, including screenshots of any UI 
changes:
   The approaches discussed in 
https://apache-airflow.slack.com/archives/CCQ7EGB1P/p1559134166151100 to 
include 'params' as a templated_fields has to modified a bit to solve the issue.
   
   The discussed approaches templates the params dict. However, to make in 
available for the other templated fields in the operators, it is also required 
to update the jinja_template_context with the rendered params dict.  
   
   Hence, params templates are updated in the template_context similar to 
user_defined_macros.
   
   ### Tests
   
   - [ ] My PR adds the python operator params are templatized case to test the 
functionality. 
   The optional args of python operator contains params dict key which is 
substituted with rendered value. 
   
   ### Code Quality
   
   - [ ] Passes `flake8`
   
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Make params dict to be templated for operators
> ----------------------------------------------
>
>                 Key: AIRFLOW-4724
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-4724
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: core, operators
>    Affects Versions: 1.10.3
>            Reporter: jack
>            Priority: Major
>             Fix For: 1.10.4
>
>
> Currently using params dict as:
> {code:java}
> EXEC_TIMESEPOCH =  "{{ execution_date.strftime('%s') }}"
> gcs_export_uri_template_filename = 'product_dwh-' + EXEC_TIMESEPOCH + '.csv'
> upload_file_ftp_op = BashOperator(
>    task_id='upload_file_ftp_task',
>    params={'filename':gcs_export_uri_template_filename},
>    bash_command="python3.6 /home/ubuntu/airflow/scripts/ranker.py  '{{ 
> params.filename }}'  " ,
>   dag=dag)
> {code}
> Gives:
> {code:java}
> python3.6 /home/ubuntu/airflow/scripts/ranker.py  'product_dwh-{{ 
> execution_date.strftime('%s') }}.csv'{code}
>  
> The BaseOperator says:
> {code:java}
> self.params = params or {} # Available in templates!{code}
> [https://github.com/apache/airflow/blob/master/airflow/models/baseoperator.py#L343]
> But as you can see above the code wasn't templated as expected.
>  
> I worked-around this by not using params dict as:
> {code:java}
> cmd = """python3.6 /home/ubuntu/airflow/scripts/ranker.py 'product_dwh-{{ 
> execution_date.strftime('%s') }}.csv' """
> upload_file_ftp_op = BashOperator(
>     task_id='upload_file_ftp_task',
>     bash_command = cmd,
>     dag=dag){code}
> This code works perfectly and while it's simpler and better the first code 
> should have still work.
>  
> A discussion about this has been on slack:
> [https://apache-airflow.slack.com/archives/CCQ7EGB1P/p1559134166151100]
>  
> Since Slack doesn't save history forever [~feluelle] , [~dlamblin], if you 
> have something to comment please post it here so there will be a reference to 
> whomever pick this one up.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to