You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sc250072 (via GitHub)" <gi...@apache.org> on 2025/10/01 17:14:12 UTC

[PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

sc250072 opened a new pull request, #56305:
URL: https://github.com/apache/airflow/pull/56305

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   Related: https://github.com/apache/airflow/issues/38195
   
   Why
   The default implementation of DbApiHook.get_uri does not conform to the standard Teradata connection format.
   
   How
   Override sqlalchemy_url property to follow the official Teradata SQLAlchemy URI format documented here:
   https://pypi.org/project/teradatasqlalchemy/#ConnectionParameters
   
   Return the properly rendered SQLAlchemy URL in get_uri.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #56305:
URL: https://github.com/apache/airflow/pull/56305#discussion_r2404379581


##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -34,6 +34,7 @@
     except ImportError:
         from airflow.models.connection import Connection  # type: ignore[assignment]
 
+DEFAULT_DB_PORT = 1025

Review Comment:
   nit: Probably could add a link to the doc that mentions 1025 as a comment above this line.



##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):

Review Comment:
   This is technically a breaking change. @eladkal do we need to do anything?



##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):
-        """Return a connection object using sqlalchemy."""
-        conn: Connection = self.get_connection(self.get_conn_id())
-        link = f"teradatasql://{conn.login}:{conn.password}@{conn.host}"
-        connection = sqlalchemy.create_engine(link)
-        return connection
+    @property
+    def sqlalchemy_url(self) -> URL:
+        """
+         Override to return a Sqlalchemy.engine.URL object from the Teradata connection.

Review Comment:
   I'm a bit confused. override what to return the object?



##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):
-        """Return a connection object using sqlalchemy."""
-        conn: Connection = self.get_connection(self.get_conn_id())
-        link = f"teradatasql://{conn.login}:{conn.password}@{conn.host}"
-        connection = sqlalchemy.create_engine(link)
-        return connection
+    @property
+    def sqlalchemy_url(self) -> URL:
+        """
+         Override to return a Sqlalchemy.engine.URL object from the Teradata connection.

Review Comment:
   ```suggestion
           Override to return a `sqlalchemy.engine.URL` object from the Teradata connection.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "sc250072 (via GitHub)" <gi...@apache.org>.
sc250072 commented on code in PR #56305:
URL: https://github.com/apache/airflow/pull/56305#discussion_r2425467272


##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):

Review Comment:
   It will fall back to this method and return the same URL from [sqlalchemy_url](https://github.com/apache/airflow/blob/db4b534a29abe5a990d776b311f0dcb80631d65b/providers/common/sql/src/airflow/providers/common/sql/hooks/sql.py#L319). But any case, 
   I’ll re-add the function with a deprecation warning to preserve backward compatibility.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #56305:
URL: https://github.com/apache/airflow/pull/56305#discussion_r2425865019


##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):

Review Comment:
   one who uses older Teradata provider might break. (as this method has been removed and might be used), but if we're to bump major version. that should be fine



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal merged PR #56305:
URL: https://github.com/apache/airflow/pull/56305


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "sc250072 (via GitHub)" <gi...@apache.org>.
sc250072 commented on code in PR #56305:
URL: https://github.com/apache/airflow/pull/56305#discussion_r2425638929


##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):

Review Comment:
   > This is technically a breaking change. @eladkal do we need to do anything?
   
   Could you please clarify what you mean by a breaking change?
   Are you referring to the latest Teradata provider not being compatible with older Airflow versions?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "sc250072 (via GitHub)" <gi...@apache.org>.
sc250072 commented on code in PR #56305:
URL: https://github.com/apache/airflow/pull/56305#discussion_r2425441217


##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):
-        """Return a connection object using sqlalchemy."""
-        conn: Connection = self.get_connection(self.get_conn_id())
-        link = f"teradatasql://{conn.login}:{conn.password}@{conn.host}"
-        connection = sqlalchemy.create_engine(link)
-        return connection
+    @property
+    def sqlalchemy_url(self) -> URL:
+        """
+         Override to return a Sqlalchemy.engine.URL object from the Teradata connection.

Review Comment:
   https://github.com/apache/airflow/blob/db4b534a29abe5a990d776b311f0dcb80631d65b/providers/common/sql/src/airflow/providers/common/sql/hooks/sql.py#L297
   @Lee-W  to return the `sqlalchemy.engine.URL` object
   Will add the suggestion



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Build correct SQLAlchemy URI in Teradata Hook [airflow]

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #56305:
URL: https://github.com/apache/airflow/pull/56305#discussion_r2406041041


##########
providers/teradata/src/airflow/providers/teradata/hooks/teradata.py:
##########
@@ -195,12 +196,32 @@ def _get_conn_config_teradatasql(self) -> dict[str, Any]:
 
         return conn_config
 
-    def get_sqlalchemy_engine(self, engine_kwargs=None):

Review Comment:
   @sc250072 can you raise PR to re add the function to preserve backward compatibility and raise deprecation warning for it? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org