[
https://issues.apache.org/jira/browse/AIRFLOW-3871?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16773330#comment-16773330
]
ASF GitHub Bot commented on AIRFLOW-3871:
-----------------------------------------
galak75 commented on pull request #4743: [AIRFLOW-3871] render Operators
template fields recursively
URL: https://github.com/apache/airflow/pull/4743
Make sure you have checked _all_ steps below.
### Jira
- [x] My PR addresses the following [Airflow
Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references
them in the PR title. For example, "\[AIRFLOW-XXX\] My Airflow PR"
- https://issues.apache.org/jira/browse/AIRFLOW-3871
- In case you are fixing a typo in the documentation you can prepend your
commit with \[AIRFLOW-XXX\], code changes always need a Jira issue.
### Description
- [x] Here are some details about my PR, including screenshots of any UI
changes:
see AIRFLOW-3871 Jira ticket description
### Tests
- [x] My PR adds the following unit tests :
4 additional unit tests in `test_python_operator.py`
### Commits
- [x] My commits all reference Jira issues in their subject lines, and I
have squashed multiple commits if they address the same issue. In addition, my
commits follow the guidelines from "[How to write a good git commit
message](http://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Documentation
- [x] In case of new functionality, my PR adds documentation that describes
how to use it.
- When adding new operators/hooks/sensors, the autoclass documentation
generation needs to be added.
- All the public functions and the classes in the PR contain docstrings
that explain what it does
### Code Quality
- [x] Passes `flake8`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Allow Jinja templating recursively on object attributes
> -------------------------------------------------------
>
> Key: AIRFLOW-3871
> URL: https://issues.apache.org/jira/browse/AIRFLOW-3871
> Project: Apache Airflow
> Issue Type: Wish
> Components: operators
> Affects Versions: 1.10.0
> Reporter: Galak
> Priority: Minor
>
> Some {{Operator}} fields can be templated (using Jinja). Template rendering
> only works for string values (either direct values or values stored in
> collections).
> But a templated string inside a custom class instance won't be rendered
> Here is my scenario:
> I have a python method {{transform_data_file}} which is designed to call a
> command object. This command object constructor
> ({{MyAwesomeDataFileTransformer}}) has parameters that could be templated.
> These templated parameters are not rendered so far (see
> {{BaseOperator.render_template_from_field}} method).
> {code}
> simple_task = PythonOperator(
> task_id='simple_task',
> provide_context=True,
> python_callable=transform_data_file,
> templates_dict={
> 'transformer': MyAwesomeDataFileTransformer(
> "/data/{{ dag.dag_id }}/{{ ts }}/input_file",
> "/data/{{ dag.dag_id }}/{{ ts }}/output_file",
> )
> },
> dag=dag
> )
> {code}
> I have 3 alternatives in mind to allow rendering inner attributes:
> # Either define an Abstract Base Class declaring an abstract method
> {{render_template}}; then my command object would have to extend this
> Abstract Base Class, and then implement {{render_template}} method.
> # Or use duck typing in {{BaseOperator.render_template_from_field}} to call
> {{render_template}} method when it exists on templated custom objects; then
> my command object would just have to implement {{render_template}} method.
> # Or traverse object attributes when rendering templates and call
> {{BaseOperator.render_template}} recursively; then my command object would
> not need any change
> My preferred solution is the 3rd one, but I would like to hear about your
> opinion on this before. Maybe is there a 4th and better solution?
> I would be glad to submit a PR if this functionality is accepted.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)