Skip to content
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

Merged

Conversation

dabla
Copy link
Contributor

@dabla dabla commented Jul 9, 2024

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.

@potiuk
Copy link
Member

potiuk commented Jul 9, 2024

Small request :). PLEASE make sure to have empty line before -- in issue description - otherwise the last paragraph is rendered as heading in GitHub issue :D

@dabla
Copy link
Contributor Author

dabla commented Jul 9, 2024

Small request :). PLEASE make sure to have empty line before -- in issue description - otherwise the last paragraph is rendered as heading in GitHub issue :D

Yes I saw that :) Thanks for fixing that Jarek 👍

@dabla dabla marked this pull request as draft July 17, 2024 09:14
@dabla dabla marked this pull request as ready for review July 17, 2024 15:11
@dabla
Copy link
Contributor Author

dabla commented Jul 19, 2024

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.

@potiuk
Copy link
Member

potiuk commented Jul 19, 2024

failed when fatching remote inventory.

Copy link
Member

@potiuk potiuk left a 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.

@potiuk potiuk force-pushed the feature/create-sql-alchemy-engine-from-db-conn branch from 14a6489 to bef02a3 Compare July 26, 2024 10:33
@potiuk
Copy link
Member

potiuk commented Jul 26, 2024

Rebased to see if it still works in main.

@dabla
Copy link
Contributor Author

dabla commented Jul 26, 2024

Rebased to see if it still works in main.

Thank you @potiuk, cannot check it myself right now on vacation 😉

@potiuk potiuk merged commit f6c7388 into apache:main Jul 26, 2024
53 checks passed
@utkarsharma2 utkarsharma2 added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) provider:common-sql
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants