Skip to content

Commit 974d5f0

Browse files
authored
fix: catching the wrong exception class (#68)
1 parent 1fd334d commit 974d5f0

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

aws_wrapper/dialect.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
from contextlib import closing
1919
from enum import Enum, auto
2020
from logging import getLogger
21-
from typing import Dict, Optional, Protocol, Tuple, runtime_checkable
21+
from typing import (TYPE_CHECKING, Dict, Optional, Protocol, Tuple,
22+
runtime_checkable)
23+
24+
if TYPE_CHECKING:
25+
from aws_wrapper.pep249 import Connection
2226

2327
from aws_wrapper.errors import AwsWrapperError
2428
from aws_wrapper.hostinfo import HostInfo
25-
from aws_wrapper.pep249 import Connection, Error
2629
from aws_wrapper.utils.properties import (Properties, PropertiesUtils,
2730
WrapperProperties)
2831
from aws_wrapper.utils.rdsutils import RdsUtils
@@ -162,7 +165,7 @@ def is_dialect(self, conn: Connection) -> bool:
162165
for column_value in record:
163166
if "mysql" in column_value.lower():
164167
return True
165-
except Error:
168+
except Exception:
166169
pass
167170

168171
return False
@@ -203,8 +206,10 @@ def is_dialect(self, conn: Connection) -> bool:
203206
aws_cursor.execute('SELECT 1 FROM pg_proc LIMIT 1')
204207
if aws_cursor.fetchone() is not None:
205208
return True
206-
except Error:
207-
pass
209+
except Exception:
210+
# Executing the select statements will start a transaction, if the queries failed due to invalid syntax,
211+
# the transaction will be aborted, no further commands can be executed. We need to call rollback here.
212+
conn.rollback()
208213

209214
return False
210215

@@ -252,7 +257,7 @@ def is_dialect(self, conn: Connection) -> bool:
252257
for record in aws_cursor:
253258
if "mariadb" in record[0].lower():
254259
return True
255-
except Error:
260+
except Exception:
256261
pass
257262

258263
return False
@@ -286,7 +291,7 @@ def is_dialect(self, conn: Connection) -> bool:
286291
for column_value in record:
287292
if "source distribution" in column_value.lower():
288293
return True
289-
except Error:
294+
except Exception:
290295
pass
291296

292297
return False
@@ -318,8 +323,10 @@ def is_dialect(self, conn: Connection) -> bool:
318323
if rds_tools and not aurora_utils:
319324
return True
320325

321-
except Error:
322-
pass
326+
except Exception:
327+
# Executing the select statements will start a transaction, if the queries failed due to invalid syntax,
328+
# the transaction will be aborted, no further commands can be executed. We need to call rollback here.
329+
conn.rollback()
323330
return False
324331

325332
@property
@@ -345,7 +352,7 @@ def is_dialect(self, conn: Connection) -> bool:
345352
# If variable with such a name is presented then it means it's an Aurora cluster
346353
if aws_cursor.fetchone() is not None:
347354
return True
348-
except Error:
355+
except Exception:
349356
pass
350357

351358
return False
@@ -392,8 +399,10 @@ def is_dialect(self, conn: Connection) -> bool:
392399
has_topology = True
393400

394401
return has_extensions and has_topology
395-
except Error:
396-
pass
402+
except Exception:
403+
# Executing the select statements will start a transaction, if the queries failed due to invalid syntax,
404+
# the transaction will be aborted, no further commands can be executed. We need to call rollback here.
405+
conn.rollback()
397406

398407
return False
399408

aws_wrapper/failover_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, plugin_service: PluginService, props: Properties):
6767
self._last_exception: Optional[Exception] = None
6868
self._rds_utils = RdsUtils()
6969
self._rds_url_type: RdsUrlType = self._rds_utils.identify_rds_type(self._properties.get("host"))
70-
FailoverPlugin._SUBSCRIBED_METHODS.add(*self._plugin_service.network_bound_methods)
70+
FailoverPlugin._SUBSCRIBED_METHODS.update(*self._plugin_service.network_bound_methods)
7171

7272
def init_host_provider(
7373
self,

0 commit comments

Comments
 (0)