From b3904b6ecb14cd0bbb69fa10efaeb754e53572b9 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 21 Dec 2025 15:18:20 +0100 Subject: [PATCH] fix: Fix handling of absolute paths for SQLCipher databases (#20074) * sequential * zero default * fix * fix: preserve absolute paths in sqlite+sqlcipher URLs Previously, the connection logic incorrectly stripped the leading slash from `sqlite+sqlcipher` paths, forcibly converting absolute paths (e.g., `sqlite+sqlcipher:////app/data.db`) into relative paths (which became `app/data.db`). This caused database initialization failures when using absolute paths, such as with Docker volume mounts. This change removes the slash-stripping logic, ensuring that absolute path conventions (starting with `/`) are respected while maintaining support for relative paths (which do not start with `/`). --- backend/open_webui/internal/db.py | 3 +-- backend/open_webui/internal/wrappers.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/internal/db.py b/backend/open_webui/internal/db.py index d4c25e459b..e3fbffcf23 100644 --- a/backend/open_webui/internal/db.py +++ b/backend/open_webui/internal/db.py @@ -90,8 +90,7 @@ if SQLALCHEMY_DATABASE_URL.startswith("sqlite+sqlcipher://"): # Extract database path from SQLCipher URL db_path = SQLALCHEMY_DATABASE_URL.replace("sqlite+sqlcipher://", "") - if db_path.startswith("/"): - db_path = db_path[1:] # Remove leading slash for relative paths + # Create a custom creator function that uses sqlcipher3 def create_sqlcipher_connection(): diff --git a/backend/open_webui/internal/wrappers.py b/backend/open_webui/internal/wrappers.py index b1b2a2ba23..e33bb3d3a4 100644 --- a/backend/open_webui/internal/wrappers.py +++ b/backend/open_webui/internal/wrappers.py @@ -54,8 +54,7 @@ def register_connection(db_url): # Parse the database path from SQLCipher URL # Convert sqlite+sqlcipher:///path/to/db.sqlite to /path/to/db.sqlite db_path = db_url.replace("sqlite+sqlcipher://", "") - if db_path.startswith("/"): - db_path = db_path[1:] # Remove leading slash for relative paths + # Use Peewee's native SqlCipherDatabase with encryption db = SqlCipherDatabase(db_path, passphrase=database_password)