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

Suppress JException when get_autocommit and set_autocommit methods aren't supported on JDBC driver #43786

Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
da67db3
refactor: get_autocommit and set_autocommit should also suppress JExc…
davidblain-infrabel Nov 7, 2024
37a2b90
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 7, 2024
9f7287b
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 7, 2024
391e4a6
refactor: Use the cached connection property instead of get_connectio…
davidblain-infrabel Nov 8, 2024
fa6a89c
refactor: Bumped version of jdbc provider to 4.5.3
davidblain-infrabel Nov 8, 2024
8c5edf5
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 8, 2024
45239c4
Update providers/src/airflow/providers/jdbc/provider.yaml
potiuk Nov 12, 2024
886119d
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 12, 2024
a377bde
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 12, 2024
f0a6073
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 12, 2024
925d3a8
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 12, 2024
274d591
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 12, 2024
b48e494
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 12, 2024
a433aa5
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 13, 2024
e4297b3
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 15, 2024
d77c569
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 18, 2024
c6fe6df
Merge branch 'main' into fix/also-suppress-jexception-in-jdbc-hook-wh…
dabla Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions providers/src/airflow/providers/jdbc/hooks/jdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import TYPE_CHECKING, Any

import jaydebeapi
import jpype
from sqlalchemy.engine import URL

from airflow.exceptions import AirflowException
Expand Down Expand Up @@ -148,7 +149,7 @@ def driver_class(self) -> str | None:

@property
def sqlalchemy_url(self) -> URL:
conn = self.get_connection(getattr(self, self.conn_name_attr))
conn = self.connection
sqlalchemy_scheme = conn.extra_dejson.get("sqlalchemy_scheme")
if sqlalchemy_scheme is None:
raise AirflowException(
Expand Down Expand Up @@ -177,7 +178,7 @@ def get_sqlalchemy_engine(self, engine_kwargs=None):
return super().get_sqlalchemy_engine(engine_kwargs)

def get_conn(self) -> jaydebeapi.Connection:
conn: Connection = self.get_connection(self.get_conn_id())
conn: Connection = self.connection
host: str = conn.host
login: str = conn.login
psw: str = conn.password
Expand All @@ -197,7 +198,7 @@ def set_autocommit(self, conn: jaydebeapi.Connection, autocommit: bool) -> None:
:param conn: The connection.
:param autocommit: The connection's autocommit setting.
"""
with suppress_and_warn(jaydebeapi.Error):
with suppress_and_warn(jaydebeapi.Error, jpype.JException):
conn.jconn.setAutoCommit(autocommit)

def get_autocommit(self, conn: jaydebeapi.Connection) -> bool:
Expand All @@ -209,6 +210,6 @@ def get_autocommit(self, conn: jaydebeapi.Connection) -> bool:
to True on the connection. False if it is either not set, set to
False, or the connection does not support auto-commit.
"""
with suppress_and_warn(jaydebeapi.Error):
with suppress_and_warn(jaydebeapi.Error, jpype.JException):
return conn.jconn.getAutoCommit()
return False