[GH-ISSUE #20561] issue: [Bug] Code interpreter images fail to render - "Object of type function is not JSON serializable" in file upload (v0.7.1/v0.7.2) #57890

Closed
opened 2026-05-05 21:51:35 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @4republic on GitHub (Jan 10, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/20561

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.7.2 (also confirmed in v0.7.1)

Ollama Version (if applicable)

N/A (issue occurs with OpenAI-compatible APIs via LiteLLM)

Operating System

Win 11 Docker container WSL2

Browser (if applicable)

No response

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 provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

When code interpreter generates a matplotlib/plotly chart, the image should be saved to the database and rendered inline in the chat as a visible image.

Actual Behavior

Code interpreter successfully generates the image, but the file upload to the database fails with a JSON serialization error. Instead of a rendered image, the raw base64 string is dumped into the chat as text:
Company Comparison
The "Analyzing..." spinner may also continue indefinitely even after the chat is marked complete

Steps to Reproduce

  1. Fresh Open WebUI v0.7.2 installation via Docker (ghcr.io/open-webui/open-webui:main)
  2. Configure any OpenAI-compatible model (tested with Grok 4.1, Gemini 3 Flash via LiteLLM)
  3. Enable Code Interpreter capability on the model (Admin → Models → [model] → Capabilities → Code Interpreter: ON)
  4. Start a new chat with that model
  5. Send prompt: "Create a bar chart with matplotlib showing: Acuity 4.1, Signify 7.2, Hubbell 5.6, Legrand 8.9"
  6. Code interpreter executes successfully, generates Python code, runs matplotlib
  7. Image generation succeeds (file is created at /app/backend/data/uploads/)
  8. Database INSERT fails when saving file metadata
  9. Raw base64 string appears in chat instead of rendered image

Logs & Screenshots

Error from Docker logs:
sqlalchemy.exc.StatementError: (builtins.TypeError) Object of type function is not JSON serializable
[SQL: INSERT INTO file (id, user_id, hash, filename, path, data, meta, access_control, created_at, updated_at) VALUES (%(id)s, %(user_id)s, %(hash)s, %(filename)s, %(path)s, %(data)s::JSON, %(meta)s::JSON, %(access_control)s::JSON, %(created_at)s, %(updated_at)s)]
[parameters: [{'meta': {'name': 'generated-image.png', 'content_type': 'image/png', 'size': 24622, 'data': {...}}, ...}]]

2026-01-10 21:29:25.470 | ERROR | open_webui.routers.files:upload_file_handler:336 - 400: [ERROR: Error uploading file]

Stack trace points to:

/app/backend/open_webui/utils/middleware.py, line 3538: get_image_url_from_base64()
/app/backend/open_webui/utils/files.py, line 70: upload_image()
/app/backend/open_webui/routers/images.py, line 512: upload_image()
/app/backend/open_webui/routers/files.py, line 330: upload_file_handler() - HTTPException raised

Root cause: The meta dictionary being passed to upload_file_handler() contains a Python function object that cannot be serialized to JSON when inserting into PostgreSQL.

Screenshot:

Image

Additional Information

Regression: This appears to be a regression introduced in v0.7.x. Code interpreter image rendering worked in v0.6.x.
Database: PostgreSQL (default Docker setup)
Workaround: Using Mermaid diagrams instead of matplotlib bypasses the issue since Mermaid renders client-side without file uploads.
Secondary symptom: The frontend "Analyzing..." spinner may continue spinning indefinitely after the error occurs, even though the backend returns HTTP 200 on /api/chat/completed.

The issue is in how the meta parameter is constructed before being passed to upload_file_handler(). A function reference is being included in the dict. The fix would be in one of:

/app/backend/open_webui/utils/middleware.py around line 3538
/app/backend/open_webui/utils/files.py around line 70
/app/backend/open_webui/routers/images.py around line 512

The meta dict should be sanitized to ensure all values are JSON-serializable before the database INSERT.

Originally created by @4republic on GitHub (Jan 10, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/20561 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.7.2 (also confirmed in v0.7.1) ### Ollama Version (if applicable) N/A (issue occurs with OpenAI-compatible APIs via LiteLLM) ### Operating System Win 11 Docker container WSL2 ### Browser (if applicable) _No response_ ### 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 **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior When code interpreter generates a matplotlib/plotly chart, the image should be saved to the database and rendered inline in the chat as a visible image. ### Actual Behavior Code interpreter successfully generates the image, but the file upload to the database fails with a JSON serialization error. Instead of a rendered image, the raw base64 string is dumped into the chat as text: ![Company Comparison](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAC5kAAboCAYAAC80/SgAAAAOXRFWHRT...) The "Analyzing..." spinner may also continue indefinitely even after the chat is marked complete ### Steps to Reproduce 1. Fresh Open WebUI v0.7.2 installation via Docker (ghcr.io/open-webui/open-webui:main) 2. Configure any OpenAI-compatible model (tested with Grok 4.1, Gemini 3 Flash via LiteLLM) 3. Enable Code Interpreter capability on the model (Admin → Models → [model] → Capabilities → Code Interpreter: ON) 4. Start a new chat with that model 5. Send prompt: "Create a bar chart with matplotlib showing: Acuity 4.1, Signify 7.2, Hubbell 5.6, Legrand 8.9" 6. Code interpreter executes successfully, generates Python code, runs matplotlib 7. Image generation succeeds (file is created at /app/backend/data/uploads/) 8. Database INSERT fails when saving file metadata 9. Raw base64 string appears in chat instead of rendered image ### Logs & Screenshots Error from Docker logs: sqlalchemy.exc.StatementError: (builtins.TypeError) Object of type function is not JSON serializable [SQL: INSERT INTO file (id, user_id, hash, filename, path, data, meta, access_control, created_at, updated_at) VALUES (%(id)s, %(user_id)s, %(hash)s, %(filename)s, %(path)s, %(data)s::JSON, %(meta)s::JSON, %(access_control)s::JSON, %(created_at)s, %(updated_at)s)] [parameters: [{'meta': {'name': 'generated-image.png', 'content_type': 'image/png', 'size': 24622, 'data': {...}}, ...}]] 2026-01-10 21:29:25.470 | ERROR | open_webui.routers.files:upload_file_handler:336 - 400: [ERROR: Error uploading file] Stack trace points to: /app/backend/open_webui/utils/middleware.py, line 3538: get_image_url_from_base64() /app/backend/open_webui/utils/files.py, line 70: upload_image() /app/backend/open_webui/routers/images.py, line 512: upload_image() /app/backend/open_webui/routers/files.py, line 330: upload_file_handler() - HTTPException raised Root cause: The meta dictionary being passed to upload_file_handler() contains a Python function object that cannot be serialized to JSON when inserting into PostgreSQL. Screenshot: <img width="1993" height="1153" alt="Image" src="https://github.com/user-attachments/assets/32d6f031-4b4f-4005-a154-99eb077e481d" /> ### Additional Information Regression: This appears to be a regression introduced in v0.7.x. Code interpreter image rendering worked in v0.6.x. Database: PostgreSQL (default Docker setup) Workaround: Using Mermaid diagrams instead of matplotlib bypasses the issue since Mermaid renders client-side without file uploads. Secondary symptom: The frontend "Analyzing..." spinner may continue spinning indefinitely after the error occurs, even though the backend returns HTTP 200 on /api/chat/completed. The issue is in how the meta parameter is constructed before being passed to upload_file_handler(). A function reference is being included in the dict. The fix would be in one of: /app/backend/open_webui/utils/middleware.py around line 3538 /app/backend/open_webui/utils/files.py around line 70 /app/backend/open_webui/routers/images.py around line 512 The meta dict should be sanitized to ensure all values are JSON-serializable before the database INSERT.
GiteaMirror added the bug label 2026-05-05 21:51:36 -05:00
Author
Owner

@pr-validator-bot commented on GitHub (Jan 10, 2026):

⚠️ Invalid Issue Title

Hey @4republic, please provide a descriptive title for your issue. Titles that are empty, very short (under 10 characters), or generic (like "issue:") make it difficult for volunteer contributors to understand and triage issues.

Please update the title to reflect the content of your issue.

<!-- gh-comment-id:3733585896 --> @pr-validator-bot commented on GitHub (Jan 10, 2026): # ⚠️ Invalid Issue Title Hey @4republic, please provide a descriptive title for your issue. Titles that are empty, very short (under 10 characters), or generic (like "issue:") make it difficult for volunteer contributors to understand and triage issues. Please update the title to reflect the content of your issue.
Author
Owner

@Classic298 commented on GitHub (Jan 11, 2026):

have a possible fix lined up

<!-- gh-comment-id:3734626790 --> @Classic298 commented on GitHub (Jan 11, 2026): have a possible fix lined up
Author
Owner

@Classic298 commented on GitHub (Jan 11, 2026):

I fully tested this on my end @4republic

https://github.com/open-webui/open-webui/pull/20590

But i dont have PSQL, only sqlite. Please also test the PR on your end to verify this fixed your issue

<!-- gh-comment-id:3734647057 --> @Classic298 commented on GitHub (Jan 11, 2026): I fully tested this on my end @4republic https://github.com/open-webui/open-webui/pull/20590 But i dont have PSQL, only sqlite. Please also test the PR on your end to verify this fixed your issue
Author
Owner

@rozatoo commented on GitHub (Jan 12, 2026):

Works on my v0.07.2 instance with PSQL!

Image

Applied fix with:
curl -sL https://github.com/open-webui/open-webui/pull/20590.patch | git apply - + rebuild

<!-- gh-comment-id:3737176958 --> @rozatoo commented on GitHub (Jan 12, 2026): Works on my v0.07.2 instance with PSQL! <img width="780" height="696" alt="Image" src="https://github.com/user-attachments/assets/82bed3a3-f4bb-439b-88c2-3b158f921bd9" /> Applied fix with: `curl -sL https://github.com/open-webui/open-webui/pull/20590.patch | git apply -` + rebuild
Author
Owner

@Classic298 commented on GitHub (Jan 12, 2026):

@tjbck

<!-- gh-comment-id:3737208691 --> @Classic298 commented on GitHub (Jan 12, 2026): @tjbck
Author
Owner

@4republic commented on GitHub (Jan 18, 2026):

I haven't had a chance to apply the patch myself, but given rozatoo's confirmation, I'm satisfied this resolves the issue. Appreciate the turnaround!

<!-- gh-comment-id:3764923022 --> @4republic commented on GitHub (Jan 18, 2026): I haven't had a chance to apply the patch myself, but given rozatoo's confirmation, I'm satisfied this resolves the issue. Appreciate the turnaround!
Author
Owner

@Classic298 commented on GitHub (Jan 18, 2026):

@4republic please do test it. Your setup might differ.

<!-- gh-comment-id:3765182391 --> @Classic298 commented on GitHub (Jan 18, 2026): @4republic please do test it. Your setup might differ.
Author
Owner

@tjbck commented on GitHub (Mar 8, 2026):

Should be addressed in dev.

<!-- gh-comment-id:4020247629 --> @tjbck commented on GitHub (Mar 8, 2026): Should be addressed in dev.
Author
Owner

@Classic298 commented on GitHub (Mar 8, 2026):

1364df0913

<!-- gh-comment-id:4020248527 --> @Classic298 commented on GitHub (Mar 8, 2026): https://github.com/open-webui/open-webui/commit/1364df09136af2f30365a187ad4bf716435926e9
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#57890