-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Add Parameters to SqlToS3Operator template fields. #45466
base: main
Are you sure you want to change the base?
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
I think your example doesn't make sense. You are not using https://stackoverflow.com/a/72246305/14624409 It doesn't make sense to template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking merge till we clarify the issue
I made some edits for clarity, Thanks for the quick response! Edit let me edit/read your stackoverflow a bit more. |
So I may be confused a little as well. Are the DAG Params when rendered in SQL, eg my first example, properly SQL escaped? If so that does alleviate our concern. The team is worried about a future state where SQL injection might be possible. My assumption is that they are not and its mostly just a string insertion. Part of what might be confusing me is the SQLExecuteQueryOperator does have parameters in the The second example I wrote is using the parameters option to allow SQLAlchemy to render the |
To my perspective it's wrong but that ship has saild. I don't really mind adding it as template filed here as you requested but the example you shared doesn't reflect using
templated fields is going to have massive refactor in Airflow 3 |
I'll be honest I'm even more confused now. The task level params do not show up when you go to manually trigger a DAG. Not included in the example, which might be the issue, is the DAG definition which looks like such with DAG(
...
dag_id="demo",
schedule=None,
catchup=False,
params={
...
"date": "2024-01-01",
},
) as dag:
SqlToS3Operator(
task_id="export_sql_to_s3",
sql_conn_id="trino_chart_retrieval_ro_id",
query="""select * from foo where date > %s""",
parameters=({{params.date}},),
...
) I gave a try using the task level params, as you gave an example, sadly I could not get them to show up in the Trigger Dag UI. Is there a pattern or documentation I'm missing here? |
Isn't that templated string vulnerable to SQL injection? Passing params will go through SQLAlchemy and avoid that vulnerability. Is my understanding correct? |
Adds parameters to the template_fields for the SqlToS3Operator.
Team was writing some basic automations and we came across some use cases where we want to dynamically run some reports with parameters and the thought of direct replacement inside the SQL instead of using SQL parameters is irking.
An example of what we currently need todo.
vs with the parameters field being templated.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.