tirkarthi commented on PR #39918:
URL: https://github.com/apache/airflow/pull/39918#issuecomment-2142579113
yes, the case is taken from the linked issue but there could be other cases
where `configuration` could have some keys that are not templated but are
useful along with the overall structure being useful to debug in case of
complex json. The change also means changing the API. Right now API only
returns `configuration` value which is part of `template_fields` and doesn't
return `configuration.query.query` which is a nested value part of
`template_fields_renderers` mapping. The legacy view takes template_fields and
also renders the fields from `template_fields_renderers` as separate fields.
Since the PR has test case failure I was thinking to keep `rendered_fields`
as it is with nested values enriched and have a new field for the renderer
mapping. Something like below structure so that it doesn't break current API
and also cases where the json might have field `renderer` which will get
overridden.
Sample response :
```json
"rendered_fields": {
"configuration": {
"query": {
"query": "INSERT INTO `mylong_table_name`\n (id,\n
name,\n age)\nSELECT id,\n name,\n age\nFROM
users;"
}
},
"configuration.query.query": "INSERT INTO `mylong_table_name`\n
(id,\n name,\n age)\nSELECT id,\n name,\n
age\nFROM users;",
"project_id": 1
},
"rendered_fields_mapping": {
"configuration": "json",
"configuration.query.query": "sql"
},
```
Sample operator
```python
class CustomOperator(BaseOperator):
template_fields: list[str] = (
"configuration",
"project_id",
)
template_ext: list[str] = (
".json",
".sql",
)
template_fields_renderers = {
"configuration": "json",
"configuration.query.query": "sql",
}
def __init__(self, configuration, project_id, **kwargs) -> None:
super().__init__(**kwargs)
self.configuration = configuration
self.project_id = project_id
def execute(self, context):
print(self.configuration)
return self.configuration
```
--
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]