Skip to content

Commit 387eaeb

Browse files
committed
Return None when failed to get server version in SQLAlchemy
This is the same approach as pymssql.
1 parent 4f5a1c0 commit 387eaeb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

trino/sqlalchemy/dialect.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext
1818
from sqlalchemy.engine.url import URL
1919

20-
from trino import dbapi as trino_dbapi
20+
from trino import dbapi as trino_dbapi, logging
2121
from trino.auth import BasicAuthentication
2222
from trino.dbapi import Cursor
23+
from trino.exceptions import TrinoUserError
2324
from trino.sqlalchemy import compiler, datatype, error
2425

26+
logger = logging.get_logger(__name__)
27+
2528

2629
class TrinoDialect(DefaultDialect):
2730
name = "trino"
@@ -266,11 +269,15 @@ def has_sequence(self, connection: Connection, sequence_name: str, schema: str =
266269
"""Trino has no support for sequence. Returns False indicate that given sequence does not exists."""
267270
return False
268271

269-
def _get_server_version_info(self, connection: Connection) -> Tuple[int, ...]:
272+
def _get_server_version_info(self, connection: Connection) -> Any:
270273
query = "SELECT version()"
271-
res = connection.execute(sql.text(query))
272-
version = res.scalar()
273-
return tuple([version])
274+
try:
275+
res = connection.execute(sql.text(query))
276+
version = res.scalar()
277+
return tuple([version])
278+
except TrinoUserError as e:
279+
logger.debug(f"Failed to get server version: {e.message}")
280+
return None
274281

275282
def _get_default_schema_name(self, connection: Connection) -> Optional[str]:
276283
dbapi_connection: trino_dbapi.Connection = connection.connection

0 commit comments

Comments
 (0)