From 888629acea3fe80e10a52309ebbc7ddd4db89fae Mon Sep 17 00:00:00 2001 From: Yan Wong Date: Mon, 8 Apr 2024 19:23:27 +0100 Subject: [PATCH] Update db.py Allow request.env.cmd_options to be None --- models/db.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/models/db.py b/models/db.py index ce59ef02..5b0f6a2a 100755 --- a/models/db.py +++ b/models/db.py @@ -25,10 +25,15 @@ is_testing = True ## Read configuration -if is_testing and len(request.env.cmd_options.args) > 1 and os.path.isfile(request.env.cmd_options.args[-1]): +if ( + is_testing and + request.env.cmd_options is not None and + len(request.env.cmd_options.args) > 1 and + os.path.isfile(request.env.cmd_options.args[-1]) +): # For unit testing, we might want to load a different appconfig.ini file, which can - # be passed in to the rocket server as the last arg on the command-line. - # (on the main server this is not used, and we default back to appconfig.ini + # be passed in to the rocket server as the last arg on the command-line (on the main + # server, `request.env.cmd_options` is undefined, and we default back to appconfig.ini) myconf = AppConfig(request.env.cmd_options.args[-1], reload=is_testing) else: # Reload config on each request when is_testing (i.e. not production)