Files
pgadmin4/web/pgadmin/utils/check_external_config_db.py
T
Dave Page 1058f34c52 Return False instead of raising when the external config database is unreachable. (#10052)
check_external_config_db() let connection failures and malformed URIs
propagate as exceptions. Create the engine inside the try block, return
False on any failure, and dispose of the engine in a finally block.
2026-10-12 17:16:13 +01:00

38 lines
1.4 KiB
Python

##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2026, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
from db_utils import normalize_database_uri
from sqlalchemy import create_engine, inspect
def check_external_config_db(database_uri):
"""
Check if external config database exists if it
is being used.
"""
engine = None
try:
engine = create_engine(normalize_database_uri(database_uri))
with engine.connect() as connection:
return inspect(connection).has_table("server")
except Exception:
# Anything that stops us reaching the database, a wrong password or
# an unreachable host as much as a malformed URI, is reported as
# "there is no external configuration database". The container
# entrypoint relies on that so first launch still creates the user
# from PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD (#9984)
# rather than leaving an installation nobody can log in to.
return False
finally:
# Guarded because create_engine() itself rejects a malformed URI, and
# an unbound name in the cleanup path is what caused this bug in the
# first place.
if engine is not None:
engine.dispose()