From bf7de8e7a535d1f1241657efe42c5f05b12aba9d Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Fri, 1 Jul 2022 14:50:12 +0530 Subject: [PATCH] Fixed an issue where the create_app() function was called twice if an SQLite database file was not present. Remove the exec call to run the 'setup.py' instead call the setup database function directly. --- web/pgAdmin4.py | 14 +++++--------- web/setup.py | 7 +++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 6de0bddcc..a1b81115c 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -13,7 +13,7 @@ to start a web server.""" import sys - +import setup if sys.version_info < (3, 4): raise RuntimeError('This application must be run under Python 3.4 ' @@ -82,14 +82,6 @@ class ReverseProxied(object): ########################################################################## config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION -# Check if the database exists. If it does not, create it. -if not os.path.isfile(config.SQLITE_PATH): - setup_py = os.path.join( - os.path.dirname(os.path.realpath(u_encode(__file__, fs_encoding))), - 'setup.py' - ) - exec(open(file_quote(setup_py), 'r').read()) - ########################################################################## # Create the app and configure it. It is created outside main so that @@ -99,6 +91,10 @@ app = create_app() app.debug = False app.config['sessions'] = dict() +# Check if the database exists. If it does not, create it. +if not os.path.isfile(config.SQLITE_PATH): + setup.setup_db(app) + if config.SERVER_MODE: app.wsgi_app = ReverseProxied(app.wsgi_app) diff --git a/web/setup.py b/web/setup.py index 5f4257e86..b019eaab6 100644 --- a/web/setup.py +++ b/web/setup.py @@ -86,13 +86,11 @@ def load_servers(args): load_database_servers(args.load_servers, None, load_user, True) -def setup_db(): +def setup_db(app): """Setup the configuration database.""" create_app_data_directory(config) - app = create_app() - print("pgAdmin 4 - Application Initialisation") print("======================================\n") @@ -193,4 +191,5 @@ if __name__ == '__main__': except Exception as e: print(str(e)) else: - setup_db() + app = create_app() + setup_db(app)