From b272ca5e886a8c37c7a95779656ea8dc9117732f Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 26 Jan 2026 13:24:53 +0100 Subject: [PATCH] fix: remove invalid expunge call on Pydantic FileModel (#20931) fix: remove invalid expunge call on Pydantic FileModel Files.get_file_by_id() returns a Pydantic FileModel, not an SQLAlchemy ORM object. Calling db.expunge() on a Pydantic model fails with UnmappedInstanceError since it lacks _sa_instance_state. The expunge was also unnecessary because subsequent DB updates already use fresh sessions via get_db() context manager. Fixes #20925 --- backend/open_webui/routers/retrieval.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index 4a493a34c..31df31f23 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -1771,13 +1771,12 @@ def process_file( } else: try: - # Release the database connection relative to the 'file' object - # to prevent holding the connection during the slow embedding step. - db.expunge(file) + # Commit any pending changes before the slow embedding step. + # Note: file is already a Pydantic model (not ORM), so no expunge needed. db.commit() # External embedding API takes time (5-60s+). - # No DB connection is held here. + # Subsequent updates use fresh sessions via get_db(). result = save_docs_to_vector_db( request, docs=docs,