Skip to content

Commit b3667fc

Browse files
authored
sqlalchemy optional in presto provider (#59944)
1 parent de44245 commit b3667fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

providers/presto/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ dependencies = [
7474
"google" = [
7575
"apache-airflow-providers-google"
7676
]
77+
"sqlalchemy" = [
78+
"sqlalchemy>=1.4.49",
79+
]
7780

7881
[dependency-groups]
7982
dev = [
@@ -85,6 +88,7 @@ dev = [
8588
"apache-airflow-providers-google",
8689
# Additional devel dependencies (do not remove this line and add extra development dependencies)
8790
"apache-airflow-providers-common-sql[pandas,polars]",
91+
"apache-airflow-providers-presto[sqlalchemy]",
8892
]
8993

9094
# To build docs:

providers/presto/src/airflow/providers/presto/hooks/presto.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from deprecated import deprecated
2626
from prestodb.exceptions import DatabaseError
2727
from prestodb.transaction import IsolationLevel
28-
from sqlalchemy.engine import URL
2928

3029
from airflow.configuration import conf
3130
from airflow.exceptions import AirflowOptionalProviderFeatureException, AirflowProviderDeprecationWarning
@@ -42,6 +41,8 @@
4241
)
4342

4443
if TYPE_CHECKING:
44+
from sqlalchemy.engine import URL
45+
4546
from airflow.models import Connection
4647

4748
T = TypeVar("T")
@@ -150,6 +151,14 @@ def get_conn(self) -> Connection:
150151
@property
151152
def sqlalchemy_url(self) -> URL:
152153
"""Return a `sqlalchemy.engine.URL` object constructed from the connection."""
154+
try:
155+
from sqlalchemy.engine import URL
156+
except (ImportError, ModuleNotFoundError) as err:
157+
raise AirflowOptionalProviderFeatureException(
158+
"SQLAlchemy is not installed. Please install it with "
159+
"`pip install 'apache-airflow-providers-presto[sqlalchemy]'`."
160+
) from err
161+
153162
conn = self.get_connection(self.get_conn_id())
154163
extra = conn.extra_dejson or {}
155164

0 commit comments

Comments
 (0)