From 17a45109f46b957388b29cadfd829cd5c8e05b7a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 11 Oct 2017 16:28:05 -0400 Subject: [PATCH] Bypass PostgreSQL 9.4 check if database is inaccessible --- netbox/netbox/__init__.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/netbox/netbox/__init__.py b/netbox/netbox/__init__.py index 74a9061a3..361659e58 100644 --- a/netbox/netbox/__init__.py +++ b/netbox/netbox/__init__.py @@ -1,12 +1,18 @@ from distutils.version import StrictVersion from django.db import connection +from django.db.utils import OperationalError -# NetBox v2.2 and later requires PostgreSQL 9.4 or higher -with connection.cursor() as cursor: - cursor.execute("SELECT VERSION()") - row = cursor.fetchone() - pg_version = row[0].split()[1] - if StrictVersion(pg_version) < StrictVersion('9.4.0'): - raise Exception("PostgreSQL 9.4.0 or higher is required. ({} found)".format(pg_version)) +# NetBox v2.2 and later requires PostgreSQL 9.4 or higher. +try: + with connection.cursor() as cursor: + cursor.execute("SELECT VERSION()") + row = cursor.fetchone() + pg_version = row[0].split()[1] + if StrictVersion(pg_version) < StrictVersion('9.4.0'): + raise Exception("PostgreSQL 9.4.0 or higher is required. ({} found)".format(pg_version)) + +# Skip if the database is missing (e.g. for CI testing) or misconfigured. +except OperationalError: + pass