schweizersta opened a new issue, #42344:
URL: https://github.com/apache/airflow/issues/42344
### Apache Airflow Provider(s)
standard
### Versions of Apache Airflow Providers
apache-airflow-providers-postgres==5.12.0
### Apache Airflow version
2.10.1
### Operating System
RHEL 9.4
### Deployment
Virtualenv installation
### Deployment details
Just default airflow with apache-airflow-providers-postgres
### What happened
When using "parameters" to provide params to SQLExecuteQueryOperator, they
are not available in the template. An exception ist thrown:
"jinja2.exceptions.UndefinedError: 'dict object' has no attribute '....'"
Only when given as "params" it works.
### What you think should happen instead
Both "parameters" and "params" should be usable, but currently only "params"
works.
From the docu:<br>
SQLExecuteQueryOperator provides parameters attribute which makes it
possible to dynamically inject values into your SQL requests during runtime.
The BaseOperator class has the params attribute which is available to the
SQLExecuteQueryOperator by virtue of inheritance. **Both parameters and params
make it possible** to dynamically pass in parameters in many interesting ways.
### How to reproduce
Define a task using SQLExecuteQueryOperator and provide params using
"parameters" like here:
```py
sql_task = SQLExecuteQueryOperator(
task_id="task_id",
conn_id="conn_id",
sql="file.sql",
parameters={'param_01':param_01_value},
)
```
And the file.sql may look like that:
```sql
select * from table where column = '{{ params.param_01 }}'
```
Once running the DAG an error is thrown. See stacktrace below:
```
Traceback (most recent call last):
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/airflow/models/abstractoperator.py",
line 770, in _do_render_template_fields
rendered_content = self.render_template(
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/airflow/template/templater.py",
line 171, in render_template
return self._render(template, context)
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/airflow/models/abstractoperator.py",
line 725, in _render
return super()._render(template, context, dag=dag)
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/airflow/template/templater.py",
line 127, in _render
return render_template_to_string(template, context)
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/airflow/utils/helpers.py",
line 301, in render_template_to_string
return render_template(template, cast(MutableMapping[str, Any],
context), native=False)
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/airflow/utils/helpers.py",
line 296, in render_template
return "".join(nodes)
File "<template>", line 13, in root
File
"/home/user/apps/conf/venv_airflow/lib64/python3.9/site-packages/jinja2/runtime.py",
line 857, in _fail_with_undefined_error
raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'param_01'
```
### Anything else
The problem occurs every time
### 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]