romansivolobtsev opened a new issue, #33733:
URL: https://github.com/apache/airflow/issues/33733
### Apache Airflow version
2.7.0
### What happened
I'm trying to make dynamic mapping for my operator which contains template
variables. It works perfect with `.expand`, but there some strange issue with
`.expand_kwargs`
String variables passed from `expand` renders nice in all cases. But
variables passed from `expand_kwargs` renders only if I change them somehow.
Let's see the example.
```from datetime import datetime
from airflow.decorators import dag
from airflow.utils.task_group import TaskGroup
from airflow.models import BaseOperator
JINJA_VAR = '{{ data_interval_start.to_date_string() }}'
class MyOperator(BaseOperator):
template_fields = ('a', 'b')
def __init__(self, x: str, **kwargs):
super().__init__(**kwargs)
self.a = x # same objects doesn't render with expand_kwargs
self.b = x + '!' # new one always render
def execute(self, context):
self.log.info('$' * 300)
self.log.info('a: ' + self.a)
self.log.info('b: ' + self.b)
self.log.info('%' * 300)
def expand_operator(i=3):
return (
MyOperator
.partial(task_id='expand')
.expand(x=[JINJA_VAR for _ in range(i)])
)
def expand_kwargs_operator(i=3):
return (
MyOperator
.partial(task_id='expand_kwargs')
.expand_kwargs([{'x': JINJA_VAR} for _ in range(i)])
)
@dag(
dag_id='expand_test',
start_date=datetime.today(),
schedule_interval='10 0 * * *'
)
def get_dag():
with TaskGroup(group_id='task_group'):
expand_operator(3), expand_kwargs_operator(4)
dag = get_dag()
```


I tried airflow versions: 2.5.0, 2.5.3, 2.7.0
### What you think should happen instead
`expand` and `expand_kwargs` logic should be the same for rendered templates
### How to reproduce
Run my example dag
### Operating System
ubuntu 20.04
### Versions of Apache Airflow Providers
_No response_
### Deployment
Docker-Compose
### Deployment details
Tested docker images:
- apache/airflow:2.5.0-python3.10
- apache/airflow:2.5.3-python3.10
- apache/airflow:2.7.0-python3.10
CeleryExecutor with Redis and PostgreSQL
### Anything else
_No response_
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]