Skip to content

Validate preference values set via the CLI (#7346)#10047

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-7346-cli-prefs-validation
Open

Validate preference values set via the CLI (#7346)#10047
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix-7346-cli-prefs-validation

Conversation

@dpage

@dpage dpage commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #7346.

Preferences set via the CLI (setup.py set-prefs) were not validated: Preferences.save_cli wrote the raw value straight to the configuration database and always returned success, so an invalid value (e.g. a non-numeric string for an integer preference) was stored silently. The GUI path validates via _Preference.set().

Fix:

  • _Preference.set() now accepts an optional user_id, so it can be used outside a request context (the CLI has no current_user).
  • Preferences.save_cli now looks up the preference (like Preferences.save) and delegates to set(), so the value is validated against the preference type.
  • setup.py set-prefs checks the result and reports any preference whose value was invalid instead of silently claiming success.

The GUI path is unaffected (save_cli is only used by the CLI; update() calls pref.set() directly).

Changes

  • web/pgadmin/utils/preferences.py, web/setup.py
  • Release note (9.16)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@dpage, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 7 minutes and 15 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 23178d83-e21b-4cf7-b08c-d471f09f7507

📥 Commits

Reviewing files that changed from the base of the PR and between 1a8dcd8 and a868adb.

📒 Files selected for processing (3)
  • docs/en_US/release_notes_9_16.rst
  • web/pgadmin/utils/preferences.py
  • web/setup.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@dpage dpage force-pushed the fix-7346-cli-prefs-validation branch 2 times, most recently from 49b4d77 to 5fb1856 Compare June 9, 2026 11:36
The CLI set-prefs path (save_pref -> Preferences.save_cli) wrote the raw
value to the configuration database without any type validation and
always reported success, unlike the GUI path which validates via
_Preference.set(). Route save_cli through the same set() validation
(set() now accepts an explicit user_id so it works outside a request
context), and make setup.py set-prefs check the result and report
preferences whose value was invalid.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dpage dpage force-pushed the fix-7346-cli-prefs-validation branch from 5fb1856 to a868adb Compare June 9, 2026 11:37
@asheshv asheshv requested a review from Copilot June 10, 2026 14:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes CLI preference updates (setup.py set-prefs) silently accepting invalid values by routing CLI updates through the same type-validation logic used for preference setting, and by reporting failures to the user.

Changes:

  • Extend _Preference.set() to accept an optional user_id so it can be used outside a request context.
  • Update Preferences.save_cli() to resolve the preference object and delegate to _Preference.set() for validation.
  • Update setup.py set-prefs to detect failed updates and report them; add a 9.16 release note entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
web/setup.py Checks CLI preference save result and reports failures.
web/pgadmin/utils/preferences.py Enables CLI validation by allowing _Preference.set() to target a specific user and reworking save_cli() to validate via set().
docs/en_US/release_notes_9_16.rst Adds release note for CLI preference validation fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

:param user_id: User to set the preference for; defaults to the
current user.

:returns: nothing.
Comment thread web/setup.py
Comment on lines +768 to +771
if len(invalid_value_prefs) >= 1:
print("Invalid value provided for preference(s) "
"[red]{0}[/red].".format(
(', ').join(invalid_value_prefs)))
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.

Preferences should be validated in CLI mode.

2 participants