issue: try/except block accesses undeclared variables in chat_completion handler #4784

Closed
opened 2025-11-11 16:03:07 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @lattwood on GitHub (Apr 9, 2025).

Check Existing Issues

  • I have searched the existing issues and discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.6.2

Ollama Version (if applicable)

No response

Operating System

N/A

Browser (if applicable)

curl

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have listed steps to reproduce the bug in detail.

Expected Behavior

When an exception is caught, the handler doesn't throw another uncaught exception.

Actual Behavior

If an exception is thrown in this block of code: 63533c9e3a/backend/open_webui/main.py (L1057-L1077)

It will be caught by this: 63533c9e3a/backend/open_webui/main.py (L1109-L1117)

But, metadata isn't defined as a local variable until Line 1078.

Steps to Reproduce

When I ran into this, it was while trying to directly upload a file via the API to the model to attempt to bypass any of the OCR/PyPDF handling that's done.

curl -X POST 'https://openwebui/api/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: REDACTED' \
  -d @body.json
{
    "model": "gemini-2.5-pro",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What's this file about?"
                },
                {
                    "type": "file",
                    "file": {
                    	"file_data": "data:application/pdf;base64,..."
                    }
                }
            ]
        }
    ]
}

Logs & Screenshots

Image Image

Additional Information

No response

Originally created by @lattwood on GitHub (Apr 9, 2025). ### Check Existing Issues - [x] I have searched the existing issues and discussions. - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.6.2 ### Ollama Version (if applicable) _No response_ ### Operating System N/A ### Browser (if applicable) curl ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have listed steps to reproduce the bug in detail. ### Expected Behavior When an exception is caught, the handler doesn't throw another uncaught exception. ### Actual Behavior If an exception is thrown in this block of code: https://github.com/open-webui/open-webui/blob/63533c9e3ab41edd7bd4124ef94f6b6dc09aa175/backend/open_webui/main.py#L1057-L1077 It will be caught by this: https://github.com/open-webui/open-webui/blob/63533c9e3ab41edd7bd4124ef94f6b6dc09aa175/backend/open_webui/main.py#L1109-L1117 But, `metadata` isn't defined as a local variable until Line 1078. ### Steps to Reproduce When I ran into this, it was while trying to directly upload a file via the API to the model to attempt to bypass any of the OCR/PyPDF handling that's done. ```bash curl -X POST 'https://openwebui/api/chat/completions' \ -H 'Content-Type: application/json' \ -H 'Authorization: REDACTED' \ -d @body.json ``` ```json { "model": "gemini-2.5-pro", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "What's this file about?" }, { "type": "file", "file": { "file_data": "data:application/pdf;base64,..." } } ] } ] } ``` ### Logs & Screenshots <img width="624" alt="Image" src="https://github.com/user-attachments/assets/b80a168a-0be8-4e3b-b340-6e7b4de09d2b" /> <img width="741" alt="Image" src="https://github.com/user-attachments/assets/1a4b4993-1cd7-494e-8057-1bf60fb683f5" /> ### Additional Information _No response_
GiteaMirror added the bug label 2025-11-11 16:03:07 -06:00
Author
Owner

@lattwood commented on GitHub (Apr 9, 2025):

This is a duplicate of #12658

@lattwood commented on GitHub (Apr 9, 2025): This is a duplicate of #12658
Author
Owner

@tjbck commented on GitHub (Apr 9, 2025):

Addressed in dev.

@tjbck commented on GitHub (Apr 9, 2025): Addressed in dev.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#4784