Fixed an issue where AI Reports are grayed out after setting an API k…#9724
Fixed an issue where AI Reports are grayed out after setting an API k…#9724dpage wants to merge 2 commits intopgadmin-org:masterfrom
Conversation
…ey by auto-selecting the default provider. pgadmin-org#9694 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughAdded a release-note entry for Issue Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
docs/en_US/release_notes_9_14.rstweb/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>
There was a problem hiding this comment.
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 | 🟡 MinorAdd auto-selection logic to
save_preffor consistency withsave()andupdate().The
save_preffunction (CLI path viaPreferences.save_cli) is missing the auto-selection logic that was added tosave()andupdate(). 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_prefshould 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_mapandexplicit_provider_choicelogic used insave()andupdate().🤖 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_mapto a module-level constant to avoid duplication.The
_provider_mapdictionary is defined identically in bothsave()andupdate(). 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_MAPinstead of defining_provider_maplocally.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
📒 Files selected for processing (1)
web/pgadmin/preferences/__init__.py
…ey by auto-selecting the default provider. #9694
Summary by CodeRabbit
Bug Fixes
Documentation