Skip to content

Fix: Prevent Search API Key from resetting when saving other settings#12243

Merged
amanape merged 10 commits intoOpenHands:mainfrom
sarva-20:fix/settings-api-key-reset
Jan 8, 2026
Merged

Fix: Prevent Search API Key from resetting when saving other settings#12243
amanape merged 10 commits intoOpenHands:mainfrom
sarva-20:fix/settings-api-key-reset

Conversation

@sarva-20
Copy link
Copy Markdown
Contributor

@sarva-20 sarva-20 commented Jan 2, 2026

Summary of PR

This PR fixes a bug where the search_api_key would be unintentionally deleted (reset to an empty string) when a user saved other settings (like the LLM model) without re-entering the key.

The issue occurred because the backend only checked if the key was None, but the frontend sends an empty string "" for unmodified password fields. I updated the logic to ensure that both None and empty strings are ignored, preserving the existing key in the database.

Change Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Other (dependency update, docs, typo fixes, etc.)

Checklist

  • I have read and reviewed the code and I understand what the code is doing.
  • I have tested the code to the best of my ability and ensured it works as expected.

Fixes

Resolves #9497

Release Notes

  • Include this change in the Release Notes.
    Description: Fixed a bug where the Search API Key was getting reset when saving other settings.

Copy link
Copy Markdown
Collaborator

@malhotra5 malhotra5 left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! It would be great if we can add a unit test that replicates this bug and is then passing from the code changes

@sarva-20
Copy link
Copy Markdown
Contributor Author

sarva-20 commented Jan 3, 2026

Thanks for the review! I'm working on adding a unit test for this case right now.

@sarva-20
Copy link
Copy Markdown
Contributor Author

sarva-20 commented Jan 3, 2026

@malhotra5
Thank you for your earlier feedback.

I have updated the PR with the following changes:

Unit Testing: I added a comprehensive unit test (tests/unit/server/routes/test_settings_api.py) that successfully reproduces the original issue and verifies the fix.

Code Quality: I have resolved all linting and formatting issues to ensure compliance with the project's style guidelines.

All CI checks are now passing. This pull request is ready for your final review.

@sarva-20 sarva-20 requested a review from malhotra5 January 6, 2026 18:21
Copy link
Copy Markdown
Contributor

@amanape amanape left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@amanape amanape dismissed malhotra5’s stale review January 8, 2026 15:29

Comment has been addressed

@amanape amanape merged commit a40f7bd into OpenHands:main Jan 8, 2026
22 checks passed
@sarva-20 sarva-20 deleted the fix/settings-api-key-reset branch January 8, 2026 15:52
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.

[Bug]: The search API Key gets reset when you save settings

3 participants