Skip to content

fix: Clears api_base in config when cleared from frontend settings page#762

Open
rohankshah wants to merge 1 commit into
srbhr:mainfrom
rohankshah:fix/config-api-base-url-clearing
Open

fix: Clears api_base in config when cleared from frontend settings page#762
rohankshah wants to merge 1 commit into
srbhr:mainfrom
rohankshah:fix/config-api-base-url-clearing

Conversation

@rohankshah
Copy link
Copy Markdown

@rohankshah rohankshah commented Apr 22, 2026

Pull Request Title

Clears api_base in config when cleared from frontend settings page

Related Issue

#760

Description

A stale value for api_base persisted in the config after adding it and removing it. This made it impossible for the user to clear it.

Type

  • Bug Fix
  • Feature Enhancement
  • Documentation Update
  • Code Refactoring
  • Other (please specify):

Proposed Changes

Set the api_base value to empty string even when the request doesn't have api_base value

stored["api_base"] = request.api_base if request.api_base is not None else ""

Added a test case to apps/backend/tests/integration/test_config_api.py

How to Test

  1. Open settings page on the web UI
  2. Add an Base Url value to the llm provider and click Save
  3. Remove the Base Url value and click Save.
  4. Reload the page and see the value doesn't persist

Checklist

  • The code compiles successfully without any errors or warnings
  • The changes have been tested and verified
  • The documentation has been updated (if applicable)
  • The changes follow the project's coding guidelines and best practices
  • The commit messages are descriptive and follow the project's guidelines
  • All tests (if applicable) pass successfully
  • This pull request has been linked to the related issue (if applicable)

Summary by cubic

Fixes stale api_base values in config when users clear the Base URL in the settings UI. Clearing now persists correctly so users can remove a custom base URL.

  • Bug Fixes
    • Always set api_base to an empty string when the request omits it in update_llm_config.
    • Added an integration test that sets and then clears api_base via /api/v1/config/llm-api-key.

Written for commit 01463b3. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/backend/app/routers/config.py">

<violation number="1" location="apps/backend/app/routers/config.py:138">
P2: PUT config update now clears `api_base` when omitted, causing unintended loss of saved base URL on partial updates.</violation>
</file>

<file name="apps/backend/tests/integration/test_config_api.py">

<violation number="1" location="apps/backend/tests/integration/test_config_api.py:55">
P2: The test does not persist state between requests, so it cannot verify that a stale `api_base` is actually cleared across reloads.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

if request.api_base is not None:
stored["api_base"] = request.api_base

stored["api_base"] = request.api_base if request.api_base is not None else ""
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: PUT config update now clears api_base when omitted, causing unintended loss of saved base URL on partial updates.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/backend/app/routers/config.py, line 138:

<comment>PUT config update now clears `api_base` when omitted, causing unintended loss of saved base URL on partial updates.</comment>

<file context>
@@ -134,8 +134,9 @@ async def update_llm_config(
-    if request.api_base is not None:
-        stored["api_base"] = request.api_base
+
+    stored["api_base"] = request.api_base if request.api_base is not None else ""
+
     if request.reasoning_effort is not None:
</file context>
Suggested change
stored["api_base"] = request.api_base if request.api_base is not None else ""
if request.api_base is not None:
stored["api_base"] = request.api_base
Fix with Cubic

@@ -46,6 +46,34 @@ async def test_put_llm_config(self, mock_load, mock_save, client):
data = resp.json()
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The test does not persist state between requests, so it cannot verify that a stale api_base is actually cleared across reloads.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/backend/tests/integration/test_config_api.py, line 55:

<comment>The test does not persist state between requests, so it cannot verify that a stale `api_base` is actually cleared across reloads.</comment>

<file context>
@@ -46,6 +46,34 @@ async def test_put_llm_config(self, mock_load, mock_save, client):
+    async def test_put_llm_config_api_base_clears(self, mock_log, mock_load, mock_save, client):
+        # Simulate storage
+        stored = {}
+        mock_load.side_effect = lambda: stored.copy()
+
+        async with client:
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant