-
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
Build correct SQLAlchemy URI in hooks based on DbApiHook
#38195
Comments
DbApiHook
DbApiHook
DbApiHook
hello @Taragolis I was checking this issue and seeing if I could fix it. airflow/airflow/models/connection.py Lines 271 to 329 in 0e8f108
Is fixing the get_uri part so that Airflow Connection URI representation becomes a valid SA URI the right way to fix this issue? |
As far as i remember, we recently discuss this case in slack. I guess better introduce
cc: @potiuk @dstandish |
@Taragolis , I am working on this PR - #38871 . This is a separate PR to just update the |
@Taragolis Why not implement another method named get_url and use that one to instantiate the SQLALchemy engine, as the engine can accept an SQLAlchemy URL object. Also the SQLAlchemy URL class has a factory method named create, which easily allows you to create the URL without the hastle of string manipulations, this is how I did it for my custom SQL operator (the one I mentioned on Slack):
Also see here the SQL documentation concerning creating URL's programmatically: https://docs.sqlalchemy.org/en/20/core/engines.html#creating-urls-programmatically I see @rawwar was first mentioning this, I think this would be a good idea and would simplify code and be less bug prone. |
There is new property which intends to returns SQL Alchemy URL, current behaviour of |
Hey Andrey think there is some confusion here. Yes we should definitly leave the get_uri method as it is (not get_url as it doesn’t exist yet) and implement a new get_url method which would then be called by the existing get_sqlalchemy_engine. |
This is how I done it in my custom SQLRowsInsertOperator:
|
Yes, adding new method is the way to go. How to do it, should be proposed and discussed in the PR, we have 20+ sql providers, and I think the proposal should be complete and explain how to deal with cases that can/cannot be mapped. Also the method should explicily - IMHO - call our sqlalachemy, ( If we decide to introduce a new "standard" method, in a product like Airflow and common API like DBApiHook, the proposal should provide answers to all the questions that users might ask in order to be mergable. It does not have to handle all of those but at least get enough error handlling and interface specification to explain what is the transition from the Connection form (in all those cases we have DBAPI implementation) -> SQLAlchemy URL. Which variations are handled, how it should work, how to map engine args etc. I don't think it can be handled by a single implementation, it's more a scaffloiding + implementation for all the implementations and it should be designed nicely with al least a handful (if not all) implementation from the above list to be quite sure that we will be able to handle those cases. |
@dabla , I think, we are indeed adding |
Body
Original discussion: https://lists.apache.org/thread/8rhmz3qh30hvkondct4sfmgk4vd07mn5
tl;dr;
DbApiHook
assumes that Airflow Connection URI representation is a valid SA URI, but it is not true and never was, it might work in simple cases, however it will fail in some complex one.airflow/airflow/providers/common/sql/hooks/sql.py
Lines 184 to 192 in 2ab6081
This task intend to track fixes into the hooks which based on
DbApiHook
.Hooks which don't overwrite invalid
DbApiHook.get_uri
implementationMySqlHook
frommysql
provider. This hook provide support for two different drivers.mysqlclient
: https://pypi.org/project/mysqlclient/mysql-connector-python
: https://pypi.org/project/mysql-connector-python/oracle
providerjdbc
providertrino
providerapache.hive
providerapache.impala
providerdatabricks
providerexasol
providerpresto
providervertica
providerteradata
providerHooks which uses
Connection.get_uri
for construct SQLAlchemy URIpostgres
provider. Connection to Postgres failed due to special characters in a password #38187, Connection id "extra" error #34456microsoft.mssql
providersqlite
providerCommitter
The text was updated successfully, but these errors were encountered: