o-nikolas commented on issue #42756:
URL: https://github.com/apache/airflow/issues/42756#issuecomment-2450750331
Hey! Thanks for reaching out with this ticket.
I hear your pain, but I'm not sure we want to go down the road of manually
casting individual types where they suit each usecase best. There are a lot of
other templated fields and we'd have to cast them all, across all operators.
This is really what the `render_template_as_native_obj` behaviour is meant for.
If that doesn't work for you because you have some types you _don't_ want
casted (the ints you mentioned) then that's a bespoke/tricky spot.
I think the most natural approach is one you mostly outlined about having a
task read in the data and cast it exactly in the way that you need for your
usecase, since again it's quite specific. It's not as unreasonable and
unmanageable as it may look at the outset, this is a fairly common paradigm
actually, we use it all the time in our dags. You can wrap the data extractor
tasks and the task they extract data for in a task group as well to reduce the
"clutter". I mocked up this example quickly based of the dag you provided and
it's quite clean in the code and the airflow UI:
```python
with DAG(
dag_id='test_dag',
schedule=None,
start_date=datetime(2024, 10, 4),
catchup=False,
render_template_as_native_obj=False
) as dag:
with TaskGroup(group_id='EcsRunTask') as ecs_run_task_group:
@task()
def network_config() -> dict:
return
json.loads(Variable.get('ecs_network_configuration_json'))
test_task: Unknown = EcsRunTaskOperator(
task_id='test_task',
cluster='my-cluster',
task_definition='my-task-definition',
launch_type='FARGATE',
overrides={
'containerOverrides': [
{
'name': 'my-container',
'environment': [
{
'name': 'ENVIRONMENT_VARIABLE_A',
'value':
'environment_variable_a_string_value'
},
{
'name': 'ENVIRONMENT_VARIABLE_B',
'value': '123456789'
}
]
}
]
},
network_configuration=network_config()
)
```
--
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]