Skip to content

Commit 2f7836d

Browse files
committed
supressing exception when finding postgres version
1 parent 37ae4ec commit 2f7836d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

piccolo/engine/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class Batch:
1515
class Engine(metaclass=ABCMeta):
1616
def __init__(self):
1717
self.check_version()
18-
self.tables = []
1918

2019
@property
2120
@abstractmethod

piccolo/engine/postgres.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from piccolo.query.base import Query
1717
from piccolo.querystring import QueryString
1818
from piccolo.utils.sync import run_sync
19+
from piccolo.utils.warnings import colored_warning
1920

2021

2122
@dataclass
@@ -220,12 +221,19 @@ def get_version(self) -> float:
220221
self._run_in_new_connection("SHOW server_version"),
221222
)
222223

223-
response: t.Sequence[t.Dict] = future.result()
224-
225-
server_version = response[0]["server_version"]
226-
major, minor, _ = server_version.split(".")
227-
version = float(f"{major}.{minor}")
228-
return version
224+
try:
225+
response: t.Sequence[t.Dict] = future.result()
226+
except ConnectionRefusedError as exception:
227+
# Suppressing the exception, otherwise importing piccolo_conf.py
228+
# containing an engine will raise an ImportError.
229+
colored_warning("Unable to connect to database")
230+
print(exception)
231+
return 0.0
232+
else:
233+
server_version = response[0]["server_version"]
234+
major, minor, _ = server_version.split(".")
235+
version = float(f"{major}.{minor}")
236+
return version
229237

230238
###########################################################################
231239

0 commit comments

Comments
 (0)