-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Create SQLAlchemy engine from connection in DB Hook and added autocommit param to insert_rows method #40669
Create SQLAlchemy engine from connection in DB Hook and added autocommit param to insert_rows method #40669
Conversation
Small request :). PLEASE make sure to have empty line before |
Yes I saw that :) Thanks for fixing that Jarek 👍 |
The documentation build failed here: https://github.com/apache/airflow/actions/runs/10004956096/job/27654856973?pr=40669 But when I run it locally with breeze no issues at all. |
failed when fatching remote inventory. |
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.
I really like the idea implemented here.
… the get_conn result to build the sqlalchemy engine
…e run method as this parameter will also be needed once whe have the SQLInsertRowsOperator
… has no attribute 'get_bind'
…ements the sqlalchemy_url property then use it, otherwise fallback to original implementation with get_uri
…chemy_scheme parameter
14a6489
to
bef02a3
Compare
Rebased to see if it still works in main. |
Thank you @potiuk, cannot check it myself right now on vacation 😉 |
Refactored the get_sqlalchemy_engine method in DbAPiHook so it's using the uri as well as the connection for creating an engine, which in most cases nowadays isn't working for a lot of database dialects anyway and which also bypasses the know issues with the get_uri method in combination with sqlalchemy that will be fixed in #39572.
Beside that this PR also added the autocommit parameter to the insert_rows method of the DbAPiHook, just like it is already the case with the run method. This is a preparation for a new PR that will introduce an SQLInsertRowsOperator, which will be a convenient operator allowing you to insert rows using an operator instead of the need to use a PythonOperator in combination with the already existing insert_rows method of the DbApiHook, that way it will be directly possible to pass an XCom containing the rows to persist to the operator which aren't directly feasible by using the GenericTransfer operator, for example in the case of have to download data from a REST endpoint and persisting it directly to a database.
^ 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.