[PR #21913] [CLOSED] fix: correct else block indentation in tools_dict handler (middleware.py) #41964

Closed
opened 2026-04-25 14:02:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21913
Author: @ege-gungordu
Created: 2/27/2026
Status: Closed

Base: mainHead: fix/tools-dict-else-indentation


📝 Commits (1)

  • cccd416 fix: correct indentation of else block in tools_dict handler

📊 Changes

1 file changed (+9 additions, -9 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+9 -9)

📄 Description

Summary

  • The else block for non-native function calling in process_chat_payload was indented at the same level as if tools_dict:, incorrectly pairing it with the outer check instead of the inner if function_calling == "native" check.

Before (broken):

if tools_dict:
    if metadata.get("params", {}).get("function_calling") == "native":
        # native setup...
        ]

else:  # ← paired with 'if tools_dict:' — runs when tools_dict is EMPTY
    # non-native handler never runs when tools are present
    try:
        form_data, flags = await chat_completion_tools_handler(...)

After (fixed):

if tools_dict:
    if metadata.get("params", {}).get("function_calling") == "native":
        # native setup...
        ]

    else:  # ← correctly paired with inner 'if native:' — runs when tools present and not native
        try:
            form_data, flags = await chat_completion_tools_handler(...)

Impact

  • Non-native (default/prompt-based) tool calling was completely broken when any tools were present — the handler was never called.
  • The non-native handler was incorrectly invoked when tools_dict was empty (no tools), where it would be a no-op at best.

Test plan

  • Enable a tool in OpenWebUI with function calling set to default (non-native)
  • Confirm the tool is actually called during a chat completion
  • Enable a tool with function calling set to native — confirm it still works

🔄 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/21913 **Author:** [@ege-gungordu](https://github.com/ege-gungordu) **Created:** 2/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tools-dict-else-indentation` --- ### 📝 Commits (1) - [`cccd416`](https://github.com/open-webui/open-webui/commit/cccd416bb7fde0734bae1c8c0151bfa3a03fd498) fix: correct indentation of else block in tools_dict handler ### 📊 Changes **1 file changed** (+9 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+9 -9) </details> ### 📄 Description ## Summary - The `else` block for non-native function calling in `process_chat_payload` was indented at the same level as `if tools_dict:`, incorrectly pairing it with the outer check instead of the inner `if function_calling == "native"` check. **Before (broken):** ```python if tools_dict: if metadata.get("params", {}).get("function_calling") == "native": # native setup... ] else: # ← paired with 'if tools_dict:' — runs when tools_dict is EMPTY # non-native handler never runs when tools are present try: form_data, flags = await chat_completion_tools_handler(...) ``` **After (fixed):** ```python if tools_dict: if metadata.get("params", {}).get("function_calling") == "native": # native setup... ] else: # ← correctly paired with inner 'if native:' — runs when tools present and not native try: form_data, flags = await chat_completion_tools_handler(...) ``` ## Impact - Non-native (default/prompt-based) tool calling was **completely broken** when any tools were present — the handler was never called. - The non-native handler was incorrectly invoked when `tools_dict` was **empty** (no tools), where it would be a no-op at best. ## Test plan - [ ] Enable a tool in OpenWebUI with function calling set to default (non-native) - [ ] Confirm the tool is actually called during a chat completion - [ ] Enable a tool with function calling set to native — confirm it still works --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 14:02:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41964