From 8a308b1a885085265a9e4af75bb07dbaf4f370bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 10 May 2023 13:10:47 -0400 Subject: [PATCH] Fix database not providing the right SERVER_NAME setting value --- src/common/db/Database.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/common/db/Database.py b/src/common/db/Database.py index 947b66193..01d1a7a19 100644 --- a/src/common/db/Database.py +++ b/src/common/db/Database.py @@ -366,7 +366,10 @@ class Database: .all() ) db_ids = [service.id for service in db_services] - services = config.get("SERVER_NAME", "").split(" ") + services = config.pop("SERVER_NAME", []) + + if isinstance(services, str): + services = services.split(" ") if db_services: missing_ids = [ @@ -376,13 +379,14 @@ class Database: ] if missing_ids: - # Remove plugins that are no longer in the list + # Remove services that are no longer in the list session.query(Services).filter( Services.id.in_(missing_ids) ).delete() for key, value in deepcopy(config).items(): suffix = 0 + original_key = deepcopy(key) if self.suffix_rx.search(key): suffix = int(key.split("_")[-1]) key = key[: -len(str(suffix)) - 1] @@ -475,8 +479,8 @@ class Database: Services_settings.method: method, } ) - elif f"{key}_{suffix}" not in global_values: - global_values.append(f"{key}_{suffix}") + elif setting and original_key not in global_values: + global_values.append(original_key) global_value = ( session.query(Global_values) .with_entities( @@ -489,9 +493,6 @@ class Database: .first() ) - if not setting: - continue - if global_value is None: if value == setting.default or ( not value.strip() and setting.default is None @@ -569,11 +570,6 @@ class Database: ) if global_value is None: - if value == setting.default or ( - not value.strip() and setting.default is None - ): - continue - to_put.append( Global_values( setting_id=key, @@ -627,12 +623,6 @@ class Database: to_put = [] endl = "\n" for custom_config in custom_configs: - # config = { - # "data": custom_config["value"].replace("\\\n", "\n").encode("utf-8") - # if isinstance(custom_config["value"], str) - # else custom_config["value"].replace(b"\\\n", b"\n"), - # "method": method, - # } config = { "data": custom_config["value"].encode("utf-8") if isinstance(custom_config["value"], str) @@ -806,6 +796,11 @@ class Database: } ) + servers = " ".join(service.id for service in session.query(Services).all()) + config["SERVER_NAME"] = ( + servers if methods is False else {"value": servers, "method": "default"} + ) + return config def get_custom_configs(self) -> List[Dict[str, Any]]: