-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setting parameters in SQLExecuteQueryOperator fails (should be the same as using params) #42344
Comments
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval. |
The The parameters you are trying to add from the operators need to be passed in form Your SQL file need to look like:
|
I am not talking about DAG run parameters, but task parameters (given when instantiating SQLExecuteQueryOperator). In the previous section "Passing Parameters into SQLExecuteQueryOperator for Postgres" of the second docu link you referred to, there are 2 examples:
In the second example (where the sql command is stored in a file), one has to provide values for the sql parameters using What got me confused, is the statement at the beginning of this section, where it says: "Both parameters and params make it possible to dynamically pass in parameters in many interesting ways.". So I thougt, I can use either params or parameters in both cases. But that "parameter" is only valid for the first case and "params" only for the second one, was not obvious to me. Now that I know how it's meant to be, I leave it up to you, if you want to clarify this more in the docu or not. |
Thanks for the feedback! It is really simple and once you have made your first PR you are joining the crowd and be proud! Might take <5min. |
@jscheffl I have raised the PR to make this documentation change. Please review. |
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 is 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:
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:
And the file.sql may look like that:
Once running the DAG an error is thrown. See stacktrace below:
Anything else
The problem occurs every time
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: