From 99bece38b146982f01150ceaea728adfeecd594e Mon Sep 17 00:00:00 2001 From: Soline Date: Fri, 1 Nov 2024 10:37:42 -0400 Subject: [PATCH 1/3] Handle connection exception when checking the user --- clockwork_web/user.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clockwork_web/user.py b/clockwork_web/user.py index 986de4c3..f33d1e8f 100644 --- a/clockwork_web/user.py +++ b/clockwork_web/user.py @@ -110,7 +110,12 @@ def get(mila_email_username: str): mc = get_db() - L = list(mc["users"].find({"mila_email_username": mila_email_username})) + try: + L = list(mc["users"].find({"mila_email_username": mila_email_username})) + except: + return None + + # This is not an error from which we expect to be able to recover gracefully. # It could happen if you copied data from your database directly # using an external script, and ended up with many instances of your users. From faab50bf02ea192b7dd67a9bcf6c5353818d1be6 Mon Sep 17 00:00:00 2001 From: Soline Date: Fri, 1 Nov 2024 10:42:16 -0400 Subject: [PATCH 2/3] Black reformatting --- clockwork_web/core/users_helper.py | 6 +++--- clockwork_web/user.py | 1 - scripts/ensure_one_fake_admin_in_db.py | 1 + slurm_state/helpers/parser_helper.py | 6 +++--- slurm_state/sacct_parser.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clockwork_web/core/users_helper.py b/clockwork_web/core/users_helper.py index 303fdc1f..f847f299 100644 --- a/clockwork_web/core/users_helper.py +++ b/clockwork_web/core/users_helper.py @@ -574,9 +574,9 @@ def render_template_with_user_settings(template_name_or_list, **context): The template rendered by Flask, and containing the web_settings of the current user """ - context[ - "web_settings" - ] = current_user.get_web_settings() # used for templates (old way) + context["web_settings"] = ( + current_user.get_web_settings() + ) # used for templates (old way) # used for the actual `web_settings` variable from "base.html" (prompted by GEN-160) context["web_settings_json_str"] = json.dumps(context["web_settings"]) diff --git a/clockwork_web/user.py b/clockwork_web/user.py index f33d1e8f..0ff1dbd6 100644 --- a/clockwork_web/user.py +++ b/clockwork_web/user.py @@ -115,7 +115,6 @@ def get(mila_email_username: str): except: return None - # This is not an error from which we expect to be able to recover gracefully. # It could happen if you copied data from your database directly # using an external script, and ended up with many instances of your users. diff --git a/scripts/ensure_one_fake_admin_in_db.py b/scripts/ensure_one_fake_admin_in_db.py index f4408e0b..8761b2d8 100644 --- a/scripts/ensure_one_fake_admin_in_db.py +++ b/scripts/ensure_one_fake_admin_in_db.py @@ -2,6 +2,7 @@ Helper script to make sure testing db contains at least 1 admin user. Used for frontend admin tests. """ + from slurm_state.mongo_client import get_mongo_client from slurm_state.config import get_config diff --git a/slurm_state/helpers/parser_helper.py b/slurm_state/helpers/parser_helper.py index 01928fb2..acd60a93 100644 --- a/slurm_state/helpers/parser_helper.py +++ b/slurm_state/helpers/parser_helper.py @@ -159,9 +159,9 @@ def get_tres_key(tres_type, tres_name): {"sacct_name": "requested", "cw_name": "tres_requested"}, ] for tres_subdict_name in tres_subdict_names: - res[ - tres_subdict_name["cw_name"] - ] = {} # Initialize the "tres_allocated" and the "tres_requested" subdicts + res[tres_subdict_name["cw_name"]] = ( + {} + ) # Initialize the "tres_allocated" and the "tres_requested" subdicts for tres_subdict in v[tres_subdict_name["sacct_name"]]: tres_key = get_tres_key( tres_subdict["type"], tres_subdict["name"] diff --git a/slurm_state/sacct_parser.py b/slurm_state/sacct_parser.py index 39f87ecb..e4e82f90 100644 --- a/slurm_state/sacct_parser.py +++ b/slurm_state/sacct_parser.py @@ -158,9 +158,9 @@ def get_tres_key(tres_type, tres_name): {"sacct_name": "requested", "cw_name": "tres_requested"}, ] for tres_subdict_name in tres_subdict_names: - res[ - tres_subdict_name["cw_name"] - ] = {} # Initialize the "tres_allocated" and the "tres_requested" subdicts + res[tres_subdict_name["cw_name"]] = ( + {} + ) # Initialize the "tres_allocated" and the "tres_requested" subdicts for tres_subdict in v[tres_subdict_name["sacct_name"]]: tres_key = get_tres_key( tres_subdict["type"], tres_subdict["name"] From 4d32e5aa6a1c652624ac1f7aba569c78aca0840c Mon Sep 17 00:00:00 2001 From: Soline Date: Fri, 1 Nov 2024 10:49:37 -0400 Subject: [PATCH 3/3] Black reformatting with version 22.3.0 of black --- clockwork_web/core/users_helper.py | 6 +++--- slurm_state/helpers/parser_helper.py | 6 +++--- slurm_state/sacct_parser.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clockwork_web/core/users_helper.py b/clockwork_web/core/users_helper.py index f847f299..303fdc1f 100644 --- a/clockwork_web/core/users_helper.py +++ b/clockwork_web/core/users_helper.py @@ -574,9 +574,9 @@ def render_template_with_user_settings(template_name_or_list, **context): The template rendered by Flask, and containing the web_settings of the current user """ - context["web_settings"] = ( - current_user.get_web_settings() - ) # used for templates (old way) + context[ + "web_settings" + ] = current_user.get_web_settings() # used for templates (old way) # used for the actual `web_settings` variable from "base.html" (prompted by GEN-160) context["web_settings_json_str"] = json.dumps(context["web_settings"]) diff --git a/slurm_state/helpers/parser_helper.py b/slurm_state/helpers/parser_helper.py index acd60a93..01928fb2 100644 --- a/slurm_state/helpers/parser_helper.py +++ b/slurm_state/helpers/parser_helper.py @@ -159,9 +159,9 @@ def get_tres_key(tres_type, tres_name): {"sacct_name": "requested", "cw_name": "tres_requested"}, ] for tres_subdict_name in tres_subdict_names: - res[tres_subdict_name["cw_name"]] = ( - {} - ) # Initialize the "tres_allocated" and the "tres_requested" subdicts + res[ + tres_subdict_name["cw_name"] + ] = {} # Initialize the "tres_allocated" and the "tres_requested" subdicts for tres_subdict in v[tres_subdict_name["sacct_name"]]: tres_key = get_tres_key( tres_subdict["type"], tres_subdict["name"] diff --git a/slurm_state/sacct_parser.py b/slurm_state/sacct_parser.py index e4e82f90..39f87ecb 100644 --- a/slurm_state/sacct_parser.py +++ b/slurm_state/sacct_parser.py @@ -158,9 +158,9 @@ def get_tres_key(tres_type, tres_name): {"sacct_name": "requested", "cw_name": "tres_requested"}, ] for tres_subdict_name in tres_subdict_names: - res[tres_subdict_name["cw_name"]] = ( - {} - ) # Initialize the "tres_allocated" and the "tres_requested" subdicts + res[ + tres_subdict_name["cw_name"] + ] = {} # Initialize the "tres_allocated" and the "tres_requested" subdicts for tres_subdict in v[tres_subdict_name["sacct_name"]]: tres_key = get_tres_key( tres_subdict["type"], tres_subdict["name"]