From 92b1acd6fbb576ab799ef7a8dfbb486f7dc21564 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 25 Sep 2024 01:06:11 +0200 Subject: [PATCH] fix: RESET_CONFIG_ON_START not working --- backend/open_webui/config.py | 6 ++++++ backend/open_webui/env.py | 16 ++++------------ backend/open_webui/main.py | 5 +++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 86d8a47a3..f531a8728 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -87,6 +87,12 @@ def save_to_db(data): db.commit() +def reset_config(): + with get_db() as db: + db.query(Config).delete() + db.commit() + + # When initializing, check if config.json exists and migrate it to the database if os.path.exists(f"{DATA_DIR}/config.json"): data = load_json_config() diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 4536f91fd..bc4d94ee4 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -234,18 +234,6 @@ if FROM_INIT_PY: ).resolve() -RESET_CONFIG_ON_START = ( - os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true" -) - -if RESET_CONFIG_ON_START: - try: - os.remove(f"{DATA_DIR}/config.json") - with open(f"{DATA_DIR}/config.json", "w") as f: - f.write("{}") - except Exception: - pass - #################################### # Database #################################### @@ -265,6 +253,10 @@ if "postgres://" in DATABASE_URL: DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://") +RESET_CONFIG_ON_START = ( + os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true" +) + #################################### # WEBUI_AUTH (Required for security) #################################### diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index d190b916e..4af48906b 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -79,6 +79,7 @@ from open_webui.config import ( WEBUI_NAME, AppConfig, run_migrations, + reset_config, ) from open_webui.constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES from open_webui.env import ( @@ -92,6 +93,7 @@ from open_webui.env import ( WEBUI_SESSION_COOKIE_SAME_SITE, WEBUI_SESSION_COOKIE_SECURE, WEBUI_URL, + RESET_CONFIG_ON_START, ) from fastapi import ( Depends, @@ -187,6 +189,9 @@ https://github.com/open-webui/open-webui async def lifespan(app: FastAPI): run_migrations() + if RESET_CONFIG_ON_START: + reset_config() + asyncio.create_task(periodic_usage_pool_cleanup()) yield