Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en_US/release_notes_9_14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ Bug fixes

| `Issue #9279 <https://github.com/pgadmin-org/pgadmin4/issues/9279>`_ - Fixed an issue where OAuth2 authentication fails with 'object has no attribute' if OAUTH2_AUTO_CREATE_USER is False.
| `Issue #9392 <https://github.com/pgadmin-org/pgadmin4/issues/9392>`_ - Ensure that the Geometry Viewer refreshes when re-running queries or switching geometry columns, preventing stale data from being displayed.
| `Issue #9694 <https://github.com/pgadmin-org/pgadmin4/issues/9694>`_ - Fixed an issue where AI Reports are grayed out after setting an API key by auto-selecting the default provider.
| `Issue #9721 <https://github.com/pgadmin-org/pgadmin4/issues/9721>`_ - Fixed an issue where permissions page is not completely accessible on full scroll.
30 changes: 30 additions & 0 deletions web/pgadmin/preferences/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']])
Comment on lines +246 to +259
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don't let auto-selection override an explicit None (Disabled) choice.

If the same save payload contains default_provider='' and one of these API key/URL fields, this logic can still set default_provider back to a provider later in the loop. That makes the outcome depend on payload order and can silently re-enable AI after the user explicitly disabled it. Please skip the inference whenever pref_data already includes a default_provider update.

Possible guard
+ explicit_provider_choice = any(
+     item.get('name') == 'default_provider' for item in pref_data
+ )
  for data in pref_data:
      ...
-     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
+             str(data['value']).strip()):
          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']])

Apply the same guard in update().

Based on learnings, DEFAULT_LLM_PROVIDER = '' is intentional so AI stays disabled until the user explicitly selects a provider and supplies credentials.

Also applies to: 339-352

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/pgadmin/preferences/__init__.py` around lines 246 - 259, The
auto-selection block using _provider_map (checking data['name'] and setting
ai_module.preference('default_provider') via dp_pref.set(...)) must not override
an explicit "None/Disabled" choice in the same save payload; add a guard that
early-skips this inference when the incoming pref_data (the payload being
processed) already contains a 'default_provider' key (including empty string
''), and apply the same guard to the corresponding logic in update() (the
similar block at 339-352) so dp_pref.set is only considered if the payload does
not include an explicit default_provider update.


if not res:
return internal_server_error(errormsg=msg)

Expand Down Expand Up @@ -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
Expand Down
Loading