From 56dfa2015cbe3be937ff439827b5d357ff9fabfc Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 4 Aug 2023 09:51:41 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(settings.py):=20fix=20issue?= =?UTF-8?q?=20with=20extending=20components=5Fpath=20list=20with=20duplica?= =?UTF-8?q?te=20paths=20=E2=9C=A8=20feat(settings.py):=20add=20logging=20o?= =?UTF-8?q?f=20components=5Fpath=20and=20updated=20settings=20values=20for?= =?UTF-8?q?=20debugging=20purposes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/settings.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/settings.py b/src/backend/langflow/settings.py index 18c4a01de..439b3a1e4 100644 --- a/src/backend/langflow/settings.py +++ b/src/backend/langflow/settings.py @@ -1,3 +1,5 @@ +import contextlib +import json import os from typing import Optional, List from pathlib import Path @@ -58,10 +60,17 @@ class Settings(BaseSettings): and langflow_component_path not in value ): if isinstance(langflow_component_path, list): - value.extend(langflow_component_path) - else: + for path in langflow_component_path: + if path not in value: + value.append(path) + logger.debug( + f"Extending {langflow_component_path} to components_path" + ) + elif langflow_component_path not in value: value.append(langflow_component_path) - logger.debug(f"Adding {langflow_component_path} to components_path") + logger.debug( + f"Appending {langflow_component_path} to components_path" + ) if not value: value = [BASE_COMPONENTS_PATH] @@ -70,6 +79,7 @@ class Settings(BaseSettings): value.append(BASE_COMPONENTS_PATH) logger.debug("Adding default components path to components_path") + logger.debug(f"Components path: {value}") return value class Config: @@ -114,15 +124,22 @@ class Settings(BaseSettings): continue logger.debug(f"Updating {key}") if isinstance(getattr(self, key), list): + # value might be a '[something]' string + with contextlib.suppress(json.decoder.JSONDecodeError): + value = json.loads(str(value)) if isinstance(value, list): - getattr(self, key).extend(value) + for item in value: + if item not in getattr(self, key): + getattr(self, key).append(item) logger.debug(f"Extended {key}") else: getattr(self, key).append(value) logger.debug(f"Appended {key}") + else: setattr(self, key, value) logger.debug(f"Updated {key}") + logger.debug(f"{key}: {getattr(self, key)}") def save_settings_to_yaml(settings: Settings, file_path: str):