18
18
from contextlib import closing
19
19
from enum import Enum , auto
20
20
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
22
26
23
27
from aws_wrapper .errors import AwsWrapperError
24
28
from aws_wrapper .hostinfo import HostInfo
25
- from aws_wrapper .pep249 import Connection , Error
26
29
from aws_wrapper .utils .properties import (Properties , PropertiesUtils ,
27
30
WrapperProperties )
28
31
from aws_wrapper .utils .rdsutils import RdsUtils
@@ -162,7 +165,7 @@ def is_dialect(self, conn: Connection) -> bool:
162
165
for column_value in record :
163
166
if "mysql" in column_value .lower ():
164
167
return True
165
- except Error :
168
+ except Exception :
166
169
pass
167
170
168
171
return False
@@ -203,8 +206,10 @@ def is_dialect(self, conn: Connection) -> bool:
203
206
aws_cursor .execute ('SELECT 1 FROM pg_proc LIMIT 1' )
204
207
if aws_cursor .fetchone () is not None :
205
208
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 ()
208
213
209
214
return False
210
215
@@ -252,7 +257,7 @@ def is_dialect(self, conn: Connection) -> bool:
252
257
for record in aws_cursor :
253
258
if "mariadb" in record [0 ].lower ():
254
259
return True
255
- except Error :
260
+ except Exception :
256
261
pass
257
262
258
263
return False
@@ -286,7 +291,7 @@ def is_dialect(self, conn: Connection) -> bool:
286
291
for column_value in record :
287
292
if "source distribution" in column_value .lower ():
288
293
return True
289
- except Error :
294
+ except Exception :
290
295
pass
291
296
292
297
return False
@@ -318,8 +323,10 @@ def is_dialect(self, conn: Connection) -> bool:
318
323
if rds_tools and not aurora_utils :
319
324
return True
320
325
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 ()
323
330
return False
324
331
325
332
@property
@@ -345,7 +352,7 @@ def is_dialect(self, conn: Connection) -> bool:
345
352
# If variable with such a name is presented then it means it's an Aurora cluster
346
353
if aws_cursor .fetchone () is not None :
347
354
return True
348
- except Error :
355
+ except Exception :
349
356
pass
350
357
351
358
return False
@@ -392,8 +399,10 @@ def is_dialect(self, conn: Connection) -> bool:
392
399
has_topology = True
393
400
394
401
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 ()
397
406
398
407
return False
399
408
0 commit comments