mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #9080] [CLOSED] fix: Make sure handle_peewee_migration doesn't throw on connection error
#45361
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/9080
Author: @Kami
Created: 1/29/2025
Status: ❌ Closed
Base:
dev← Head:fix/database-connection-error-fix📝 Commits (1)
3f3d6d7fix: Make sure db is initialized to None otherwise it will fail in📊 Changes
1 file changed (+3 additions, -2 deletions)
View changed files
📝
backend/open_webui/internal/db.py(+3 -2)📄 Description
Description
This pull request updates
handle_peewee_migrationfunction so it doesn't throwUnboundLocalErrorin case code in the maintry:block throws an exception.This can happen in case the database is down, DNS name can't be resolved or any other connection related error.
Background, Context
I noticed this issue when running Open WebUI locally when docker networking was misconfiguration so the application server couldn't reach the database (PostgreSQL in my case).
Here is the full exception from the logs:
Proposed Implementation / Fix
Fix is simple. I make sure
dbis initialized toNoneat the beginning of the function (before thetryblock). This way insidefinallyblock we don't try to close the connection in case the variable is not initialized.It looks like this code was originally introduced in
d3d161f723by @tjbck, but since there is no code comment or commit description, is not clear to me why that line was originally commented out.Notes
I imagine static analysis tool such as
pylintshould catch such issues. It looks like like GHA workflow (.github/workflows/lint-backend.disabled) is disabled. It appears that was done inea7ea52ba3.If there is no special reason (e.g. too many false positives), it would be a good idea to enable it so it automatically catches minor issues and bugs like this one.
Testing
So far I only tested the change locally end to end manually, but when I get a chance and become more familiar with the development environment, I will work on adding some tests for it.
TODO
Other
Thanks to everyone who is contributed or contributed to this project and made it possible.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.