Skip to content

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

Open
dpage wants to merge 2 commits 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 2 commits 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 configuring API credentials; the default LLM provider is now automatically selected when provider credentials or URLs are added.
  • Documentation

    • Release notes updated to include the new 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

Added a release-note entry for Issue #9694 and implemented logic to auto-select a default LLM provider when a provider-specific API key or URL preference is saved/updated and no default provider has been explicitly chosen.

Changes

Cohort / File(s) Summary
Documentation
docs/en_US/release_notes_9_14.rst
Added bug-fix entry for Issue #9694 describing the auto-selection behavior for default LLM provider after setting an API key/URL.
LLM Provider Auto-Selection
web/pgadmin/preferences/__init__.py
Added provider map and explicit_provider_choice detection; on save(), update(), and update_pref() set default_provider (anthropic, openai, ollama, docker) when a provider-specific preference is populated and no explicit default exists.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Preferences
    participant AI_Module
    participant PrefStore

    User->>Preferences: Save/Update preference (e.g., openai_api_key_file)
    Preferences->>Preferences: detect explicit_provider_choice?
    alt no explicit choice and value present
        Preferences->>AI_Module: Preferences.module('ai') -> get default_provider pref
        AI_Module-->>Preferences: dp_pref (current value)
        alt dp_pref is unset
            Preferences->>PrefStore: update default_provider -> mapped provider (openai)
            PrefStore-->>Preferences: update success
        end
    end
    Preferences->>User: Return save/update result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 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 accurately describes the main fix: addressing the issue where AI Reports appear grayed out after setting an API key by implementing auto-selection of the default provider.
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

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 <noreply@anthropic.com>
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/pgadmin/preferences/__init__.py (1)

302-322: ⚠️ Potential issue | 🟡 Minor

Add auto-selection logic to save_pref for consistency with save() and update().

The save_pref function (CLI path via Preferences.save_cli) is missing the auto-selection logic that was added to save() and update(). When a user configures an API key via CLI (e.g., pgadmin-setup), the default provider won't be auto-selected, unlike when configured through the web UI. To maintain consistent behavior across all preference-setting paths, save_pref should include the same auto-selection logic:

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')
        if dp_pref and not dp_pref.get():
            dp_pref.set(_provider_map[data['name']])

Apply the same _provider_map and explicit_provider_choice logic used in save() and update().

🤖 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 302 - 322, The CLI save
path (save_pref) is missing the auto-selection of the default AI provider;
update save_pref to apply the same logic used in save() and update(): after
normalizing data['value'] but before calling Preferences.save_cli, check
explicit_provider_choice and if not set and data['name'] is in _provider_map and
data['value'] is truthy, get ai_module via Preferences.module('ai'), fetch
dp_pref via ai_module.preference('default_provider'), and if dp_pref exists and
dp_pref.get() is falsy call dp_pref.set(_provider_map[data['name']]) so the
default provider is auto-selected for CLI-configured API keys.
🧹 Nitpick comments (1)
web/pgadmin/preferences/__init__.py (1)

232-242: Extract _provider_map to a module-level constant to avoid duplication.

The _provider_map dictionary is defined identically in both save() and update(). Consider extracting it to a module-level constant near the top of the file.

♻️ Suggested refactor

Add near the top of the file (e.g., after line 30):

# Maps provider-specific preference names to their provider identifiers
# for auto-selecting the default LLM provider.
_PROVIDER_MAP = {
    'anthropic_api_key_file': 'anthropic',
    'openai_api_key_file': 'openai',
    'ollama_api_url': 'ollama',
    'docker_api_url': 'docker',
}

Then update both functions to reference _PROVIDER_MAP instead of defining _provider_map locally.

Also applies to: 334-344

🤖 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 232 - 242, Extract the
local _provider_map dict used in save() and update() into a module-level
constant named _PROVIDER_MAP near the top of the file, then replace the local
definitions of _provider_map in both save() and update() with references to
_PROVIDER_MAP; ensure the constant is documented (single-line comment) and that
save() and update() still use the same keys (e.g., 'anthropic_api_key_file',
'openai_api_key_file', 'ollama_api_url', 'docker_api_url') when checking for
explicit_provider_choice and any lookups.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@web/pgadmin/preferences/__init__.py`:
- Around line 302-322: The CLI save path (save_pref) is missing the
auto-selection of the default AI provider; update save_pref to apply the same
logic used in save() and update(): after normalizing data['value'] but before
calling Preferences.save_cli, check explicit_provider_choice and if not set and
data['name'] is in _provider_map and data['value'] is truthy, get ai_module via
Preferences.module('ai'), fetch dp_pref via
ai_module.preference('default_provider'), and if dp_pref exists and
dp_pref.get() is falsy call dp_pref.set(_provider_map[data['name']]) so the
default provider is auto-selected for CLI-configured API keys.

---

Nitpick comments:
In `@web/pgadmin/preferences/__init__.py`:
- Around line 232-242: Extract the local _provider_map dict used in save() and
update() into a module-level constant named _PROVIDER_MAP near the top of the
file, then replace the local definitions of _provider_map in both save() and
update() with references to _PROVIDER_MAP; ensure the constant is documented
(single-line comment) and that save() and update() still use the same keys
(e.g., 'anthropic_api_key_file', 'openai_api_key_file', 'ollama_api_url',
'docker_api_url') when checking for explicit_provider_choice and any lookups.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5607d905-a70f-45ce-ab51-cb8d3aebf070

📥 Commits

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

📒 Files selected for processing (1)
  • web/pgadmin/preferences/__init__.py

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