From 16fa45455850a8218e0c0d63f96ff8733900318c Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Tue, 2 Jul 2024 14:17:36 +0100 Subject: [PATCH 1/2] fix banners env --- backend/config.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/config.py b/backend/config.py index d6efde563..4a7456fd2 100644 --- a/backend/config.py +++ b/backend/config.py @@ -5,10 +5,10 @@ import importlib.metadata import pkgutil import chromadb from chromadb import Settings -from base64 import b64encode from bs4 import BeautifulSoup -from typing import TypeVar, Generic, Union +from typing import TypeVar, Generic from pydantic import BaseModel +from pydantic.error_wrappers import ValidationError from typing import Optional from pathlib import Path @@ -19,7 +19,6 @@ import markdown import requests import shutil -from secrets import token_bytes from constants import ERROR_MESSAGES #################################### @@ -768,12 +767,14 @@ class BannerModel(BaseModel): dismissible: bool timestamp: int +try: + banners = json.loads(os.environ.get("WEBUI_BANNERS", "[]")) + banners = [BannerModel(**banner) for banner in banners] +except ValidationError as e: + print(f"Error loading WEBUI_BANNERS: {e}") + banners = [] -WEBUI_BANNERS = PersistentConfig( - "WEBUI_BANNERS", - "ui.banners", - [BannerModel(**banner) for banner in json.loads("[]")], -) +WEBUI_BANNERS = PersistentConfig("WEBUI_BANNERS", "ui.banners", banners) SHOW_ADMIN_DETAILS = PersistentConfig( From 655238dcd7b71e43c7f48e30d8e7e51c56904084 Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Tue, 2 Jul 2024 14:41:59 +0100 Subject: [PATCH 2/2] banners: generic exception --- backend/config.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/config.py b/backend/config.py index 4a7456fd2..2fcc0ba64 100644 --- a/backend/config.py +++ b/backend/config.py @@ -8,7 +8,6 @@ from chromadb import Settings from bs4 import BeautifulSoup from typing import TypeVar, Generic from pydantic import BaseModel -from pydantic.error_wrappers import ValidationError from typing import Optional from pathlib import Path @@ -770,7 +769,7 @@ class BannerModel(BaseModel): try: banners = json.loads(os.environ.get("WEBUI_BANNERS", "[]")) banners = [BannerModel(**banner) for banner in banners] -except ValidationError as e: +except Exception as e: print(f"Error loading WEBUI_BANNERS: {e}") banners = []