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.
This commit is contained in:
Akshay Joshi 2022-07-01 14:50:12 +05:30
parent 9c745db413
commit bf7de8e7a5
2 changed files with 8 additions and 13 deletions

View File

@ -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)

View File

@ -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)