gnudiff commented on issue #38745:
URL: https://github.com/apache/airflow/issues/38745#issuecomment-2247694070

   Is this the same issue that when creating task via dynamic task mapping, 
references to {{ var }} and {{ params }} get lost when templating, or should I 
opend a new case?
   
   Eg. I have a custom operator created as per Airflow guide:
   
   ```
   from airflow.models import BaseOperator
   
   class CreateXMLFromTemplate(BaseOperator):
       template_fields = ('xml_file',)
       template_ext = ('.xml','.html')
   
       def __init__(
       self,
       *,
       xml_file,
       output_file,
       parameters = None,
       **kwargs,
       ):
           super().__init__(**kwargs)
           self.xml_file=xml_file
           self.parameters = parameters
           self.output_file=output_file
       
       def execute(self,context):
           with open(self.output_file,'w') as F:
               F.write(self.xml_file)
           return self.output_file
   ```
   
   
   When called via usual tasks calls, the xml_file renders all {{ var.json .... 
}} and {{ params.field }} as expected:
   
   ```
       render_xml=CreateXMLFromTemplate(
       task_id='test_xml',
       xml_file='test.xml',
       output_file='/tmp/output.xml',
       parameters={ 'cargo':{ 'prep_date':'123123' } }
       )
   ```
   
   When called via dynamic task mapping, it loses access to both {{ var }} and 
{{ params }}:
   
   ```
   @task
   def output_dynamic_task_data(): 
       results=[]
       for x in data: 
          single_result={'prep_date': xxxx }
          params=.... construct params dict
          single_result['parameters']=params
          results.append(single_result)
       return results
       
   multi_output=output_dynamic_task_data()
   
   create_xml_task=CreateXMLFromTemplate.partial(
       task_id='data_to_xml', xml_file='test.xml').expand_kwargs(multi_output)
   ```
   
   Now the same CreateXMLFromTemplate operator when parsing the same xml file 
will come up with empty for {{ var }} and {{ params }}


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to