Skip to content

Fixed an issue where AI Reports are grayed out after setting an API k…#9724

Open
dpage wants to merge 1 commit intopgadmin-org:masterfrom
dpage:fix_default_ai_provider
Open

Fixed an issue where AI Reports are grayed out after setting an API k…#9724
dpage wants to merge 1 commit intopgadmin-org:masterfrom
dpage:fix_default_ai_provider

Conversation

@dpage
Copy link
Contributor

@dpage dpage commented Mar 10, 2026

…ey by auto-selecting the default provider. #9694

Summary by CodeRabbit

  • Bug Fixes

    • AI Reports are no longer grayed out after setting an API key. The default provider is now automatically selected when API credentials are provided.
  • Documentation

    • Updated release notes with bug fix details.

…ey by auto-selecting the default provider. pgadmin-org#9694

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

A bug-fix note is added to release notes documenting Issue #9694 regarding AI Reports being grayed out. Additionally, logic is implemented to auto-select the default LLM provider when API key or URL preferences are saved or updated and no provider is currently selected.

Changes

Cohort / File(s) Summary
Documentation
docs/en_US/release_notes_9_14.rst
Added bug-fix entry for Issue #9694 describing auto-selection of default provider to resolve grayed-out AI Reports after setting API key.
LLM Provider Auto-Selection
web/pgadmin/preferences/__init__.py
Implemented automatic selection of default LLM provider (anthropic, openai, ollama, docker) when corresponding API key/URL preferences are set. Logic added to save(), update(), and update_pref() methods to populate default_provider when unset and a relevant preference value is present.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly summarizes the main change: fixing the issue where AI Reports appear grayed out after setting an API key, which matches the core functionality added across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/pgadmin/preferences/__init__.py`:
- Around line 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3843bcfe-52de-4cc1-882b-1782014c5733

📥 Commits

Reviewing files that changed from the base of the PR and between a0e6da0 and 1c034e6.

📒 Files selected for processing (2)
  • docs/en_US/release_notes_9_14.rst
  • web/pgadmin/preferences/__init__.py

Comment on lines +246 to +259
# 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']])
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.

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