From 1acfbb6755a564ba2698fbbbf6f150e88047bbd9 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 21 May 2026 16:25:25 +0400 Subject: [PATCH] refac --- backend/open_webui/internal/db.py | 6 ------ backend/open_webui/routers/utils.py | 19 +++++++------------ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/backend/open_webui/internal/db.py b/backend/open_webui/internal/db.py index e0b82dce03..496029fe5c 100644 --- a/backend/open_webui/internal/db.py +++ b/backend/open_webui/internal/db.py @@ -133,12 +133,6 @@ class JSONField(types.TypeDecorator): # TEXT-backed JSON storage return json.loads(value) if value is not None else None def copy(self, **kwargs: Any) -> Self: return JSONField(length=self.impl.length) - def db_value(self, value): - return json.dumps(value) - - def python_value(self, value): - if value is not None: - return json.loads(value) # Normalize SSL params from the URL once; the sync engine needs them diff --git a/backend/open_webui/routers/utils.py b/backend/open_webui/routers/utils.py index 9295d624c9..4d0f679955 100644 --- a/backend/open_webui/routers/utils.py +++ b/backend/open_webui/routers/utils.py @@ -96,21 +96,16 @@ async def download_chat_as_pdf(form_data: ChatTitleMessagesForm, user=Depends(ge async def download_db(user=Depends(get_admin_user)): """Download the raw SQLite database file (admin-only, SQLite deployments only).""" if not ENABLE_ADMIN_EXPORT: - raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail=ERROR_MESSAGES.ACCESS_PROHIBITED, - ) - # --- resolve target database engine --- - from open_webui.internal.db import engine # lazy — avoids circular at import time - if engine.name != 'sqlite': # non-SQLite backends use pg_dump / managed exports - raise HTTPException( - status_code=status.HTTP_400_BAD_REQUEST, - detail=ERROR_MESSAGES.DB_NOT_SQLITE, - ) + raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.ACCESS_PROHIBITED) + + # Lazy import avoids circular dependency at module load time + from open_webui.internal.db import engine + + if engine.name != 'sqlite': + raise HTTPException(status.HTTP_400_BAD_REQUEST, detail=ERROR_MESSAGES.DB_NOT_SQLITE) return FileResponse( str(engine.url.database), - media_type='application/octet-stream', filename='webui.db', )