From 1c034e60e923ea89f12cf32fd7b97b3f8f973eee Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 10 Mar 2026 12:26:51 +0000 Subject: [PATCH 1/2] Fixed an issue where AI Reports are grayed out after setting an API key by auto-selecting the default provider. #9694 Co-Authored-By: Claude Opus 4.6 --- docs/en_US/release_notes_9_14.rst | 1 + web/pgadmin/preferences/__init__.py | 30 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/en_US/release_notes_9_14.rst b/docs/en_US/release_notes_9_14.rst index f841dcd5cd5..13512c4104e 100644 --- a/docs/en_US/release_notes_9_14.rst +++ b/docs/en_US/release_notes_9_14.rst @@ -30,4 +30,5 @@ Bug fixes | `Issue #9279 `_ - Fixed an issue where OAuth2 authentication fails with 'object has no attribute' if OAUTH2_AUTO_CREATE_USER is False. | `Issue #9392 `_ - Ensure that the Geometry Viewer refreshes when re-running queries or switching geometry columns, preventing stale data from being displayed. + | `Issue #9694 `_ - Fixed an issue where AI Reports are grayed out after setting an API key by auto-selecting the default provider. | `Issue #9721 `_ - Fixed an issue where permissions page is not completely accessible on full scroll. diff --git a/web/pgadmin/preferences/__init__.py b/web/pgadmin/preferences/__init__.py index 094578c8c53..b88840acd1a 100644 --- a/web/pgadmin/preferences/__init__.py +++ b/web/pgadmin/preferences/__init__.py @@ -243,6 +243,21 @@ def save(): if data['name'] == 'save_app_state' and not data['value']: delete_tool_data() + # Auto-select the default LLM provider when an API key/URL is + # configured and no provider has been selected yet. + _provider_map = { + 'anthropic_api_key_file': 'anthropic', + 'openai_api_key_file': 'openai', + 'ollama_api_url': 'ollama', + 'docker_api_url': 'docker', + } + if res and data['name'] in _provider_map and data['value']: + ai_module = Preferences.module('ai') + if ai_module: + dp_pref = ai_module.preference('default_provider') + if dp_pref and not dp_pref.get(): + dp_pref.set(_provider_map[data['name']]) + if not res: return internal_server_error(errormsg=msg) @@ -321,6 +336,21 @@ def update(): # set user preferences pref.set(data['value']) + # Auto-select the default LLM provider when an API key/URL is + # configured and no provider has been selected yet. + _provider_map = { + 'anthropic_api_key_file': 'anthropic', + 'openai_api_key_file': 'openai', + 'ollama_api_url': 'ollama', + 'docker_api_url': 'docker', + } + if data['name'] in _provider_map and data['value']: + ai_module = Preferences.module('ai') + if ai_module: + dp_pref = ai_module.preference('default_provider') + if dp_pref and not dp_pref.get(): + dp_pref.set(_provider_map[data['name']]) + return make_json_response( data={'data': 'Success'}, status=200 From 5856b0c0bb4626af40fd1d56b7f2ed9448b4a240 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Thu, 12 Mar 2026 09:58:48 +0000 Subject: [PATCH 2/2] Don't let auto-selection override an explicit default_provider choice. If the same save payload includes a default_provider update (including setting it to empty/disabled), skip the auto-selection logic so the user's explicit choice is respected. Co-Authored-By: Claude Opus 4.6 --- web/pgadmin/preferences/__init__.py | 42 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/web/pgadmin/preferences/__init__.py b/web/pgadmin/preferences/__init__.py index b88840acd1a..13aa2532847 100644 --- a/web/pgadmin/preferences/__init__.py +++ b/web/pgadmin/preferences/__init__.py @@ -229,6 +229,18 @@ def save(): """ pref_data = get_data() + # Check once whether the user is explicitly setting default_provider + # in this save, so auto-selection doesn't override their choice. + _provider_map = { + 'anthropic_api_key_file': 'anthropic', + 'openai_api_key_file': 'openai', + 'ollama_api_url': 'ollama', + 'docker_api_url': 'docker', + } + explicit_provider_choice = any( + item.get('name') == 'default_provider' for item in pref_data + ) + for data in pref_data: if data['name'] in ['vw_edt_tab_title_placeholder', 'qt_tab_title_placeholder', @@ -245,13 +257,8 @@ def save(): # Auto-select the default LLM provider when an API key/URL is # configured and no provider has been selected yet. - _provider_map = { - 'anthropic_api_key_file': 'anthropic', - 'openai_api_key_file': 'openai', - 'ollama_api_url': 'ollama', - 'docker_api_url': 'docker', - } - if res and data['name'] in _provider_map and data['value']: + if res and not explicit_provider_choice and \ + data['name'] in _provider_map and data['value']: ai_module = Preferences.module('ai') if ai_module: dp_pref = ai_module.preference('default_provider') @@ -324,6 +331,18 @@ def update(): pref_data = get_data() pref_data = json.loads(pref_data['pref_data']) + # Check once whether the user is explicitly setting default_provider + # in this save, so auto-selection doesn't override their choice. + _provider_map = { + 'anthropic_api_key_file': 'anthropic', + 'openai_api_key_file': 'openai', + 'ollama_api_url': 'ollama', + 'docker_api_url': 'docker', + } + explicit_provider_choice = any( + item.get('name') == 'default_provider' for item in pref_data + ) + for data in pref_data: if data['name'] in ['vw_edt_tab_title_placeholder', 'qt_tab_title_placeholder', @@ -338,13 +357,8 @@ def update(): # Auto-select the default LLM provider when an API key/URL is # configured and no provider has been selected yet. - _provider_map = { - 'anthropic_api_key_file': 'anthropic', - 'openai_api_key_file': 'openai', - 'ollama_api_url': 'ollama', - 'docker_api_url': 'docker', - } - if data['name'] in _provider_map and data['value']: + if not explicit_provider_choice and \ + data['name'] in _provider_map and data['value']: ai_module = Preferences.module('ai') if ai_module: dp_pref = ai_module.preference('default_provider')