fix: Preserve image files for display in temporary chat mode
Description
Fixes image generation not displaying in temporary chat mode when using builtin tools (native function calling).
Problem
When a model is configured with builtinTools image_generation (native function calling), generated images are never shown in temporary chat mode. The image is generated server-side but the frontend never receives the file event.
The root cause is that Chats.add_message_files_by_id_and_message_id() returns None when the chat doesn't exist in the database — which is always the case for temporary chats (chat IDs starting with "local:"). The code was directly overwriting the correctly-built image_files list with this None return value, causing the event emitter to either never fire (because None is falsy) or emit files: null.
This only affects the builtin tool code path (builtinTools.image_generation: true). The older capability-based path (capabilities.image_generation: true) is unaffected because it constructs and emits the file list directly without a DB round-trip.
Fix
Store the DB return value in a separate variable and only overwrite the image file list when the DB call returns a non-None result. Applied to three locations:
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/22330
**Author:** [@Classic298](https://github.com/Classic298)
**Created:** 3/6/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `fix/temp-chat-image-display`
---
### 📝 Commits (1)
- [`1057438`](https://github.com/open-webui/open-webui/commit/10574380d1991aef7211ea1c8b58fdffe338a64f) fix: preserve image files for display in temporary chat mode
### 📊 Changes
**2 files changed** (+13 additions, -6 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/tools/builtin.py` (+6 -2)
📝 `backend/open_webui/utils/middleware.py` (+7 -4)
</details>
### 📄 Description
## fix: Preserve image files for display in temporary chat mode
### Description
Fixes image generation not displaying in temporary chat mode when using builtin tools (native function calling).
### Problem
When a model is configured with builtinTools image_generation (native function calling), generated images are never shown in temporary chat mode. The image is generated server-side but the frontend never receives the file event.
The root cause is that Chats.add_message_files_by_id_and_message_id() returns None when the chat doesn't exist in the database — which is always the case for temporary chats (chat IDs starting with "local:"). The code was directly overwriting the correctly-built image_files list with this None return value, causing the event emitter to either never fire (because None is falsy) or emit files: null.
This only affects the builtin tool code path (builtinTools.image_generation: true). The older capability-based path (capabilities.image_generation: true) is unaffected because it constructs and emits the file list directly without a DB round-trip.
### Fix
Store the DB return value in a separate variable and only overwrite the image file list when the DB call returns a non-None result. Applied to three locations:
- generate_image() in builtin.py
- edit_image() in builtin.py
- SSE streaming handler in middleware.py
### Fixes
Fixes #22309
### Contributor License Agreement
<!--
🚨 DO NOT DELETE THE TEXT BELOW 🚨
Keep the "Contributor License Agreement" confirmation text intact.
Deleting it will trigger the CLA-Bot to INVALIDATE your PR.
-->
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
> [!NOTE]
> Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/22330
Author: @Classic298
Created: 3/6/2026
Status: ❌ Closed
Base:
dev← Head:fix/temp-chat-image-display📝 Commits (1)
1057438fix: preserve image files for display in temporary chat mode📊 Changes
2 files changed (+13 additions, -6 deletions)
View changed files
📝
backend/open_webui/tools/builtin.py(+6 -2)📝
backend/open_webui/utils/middleware.py(+7 -4)📄 Description
fix: Preserve image files for display in temporary chat mode
Description
Fixes image generation not displaying in temporary chat mode when using builtin tools (native function calling).
Problem
When a model is configured with builtinTools image_generation (native function calling), generated images are never shown in temporary chat mode. The image is generated server-side but the frontend never receives the file event.
The root cause is that Chats.add_message_files_by_id_and_message_id() returns None when the chat doesn't exist in the database — which is always the case for temporary chats (chat IDs starting with "local:"). The code was directly overwriting the correctly-built image_files list with this None return value, causing the event emitter to either never fire (because None is falsy) or emit files: null.
This only affects the builtin tool code path (builtinTools.image_generation: true). The older capability-based path (capabilities.image_generation: true) is unaffected because it constructs and emits the file list directly without a DB round-trip.
Fix
Store the DB return value in a separate variable and only overwrite the image file list when the DB call returns a non-None result. Applied to three locations:
Fixes
Fixes #22309
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.