fix(cli): register module preferences before set-prefs validation#10105
Conversation
PR #10047 made `Preferences.save_cli()` validate against the registered preference object, but `setup.py set-prefs` only enters `app_context()` and never calls `run_before_app_start()`, leaving `Preferences.modules` empty. Every CLI write then fell into the "Module 'X' is no longer in use." path and was reported as "Invalid value provided". Trigger registration explicitly (run_before_app_start enters both app and test_request contexts internally, satisfying registration callbacks that touch current_user) and propagate the typed error message from save_cli so users see the actual reason a value was rejected.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangesCLI Preference Save Flow
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Summary
Preferences.save_cli()validate values against the in-memory preference object before writing, butsetup.py set-prefsonly entersapp.app_context()and never callsapp.run_before_app_start().Preferences.modulestherefore stays empty, everysave_clilookup returns(False, "Module 'X' is no longer in use."), and the CLI reports a generic "Invalid value provided" for every preference — regardless of the actual value.app.PGADMIN_RUNTIME = False+app.run_before_app_start()before the save loop.run_before_app_start()enters both an app context and atest_request_context()internally, which satisfies registration callbacks that touchcurrent_user.PGADMIN_RUNTIMEis set toFalseso the full server-mode preference set (incl. keyboard shortcuts) is exposed to the CLI.save_cliper failed preference ("Could not set <pref>: Invalid value for integer option.") instead of the aggregate generic message — useful when batching multiplekey=valuepairs of mixed types in one command or via--input-file.save_prefnow returns the(ok, msg)tuple straight fromsave_cli; its only caller issetup.py.Test plan
python setup.py set-prefs <user> "browser:display:show_user_defined_templates=true"→ savedpython setup.py set-prefs <user> "browser:display:browser_tree_state_save_interval=notanint"→ "Could not set …: Invalid value for integer option."python setup.py set-prefs <user> "browser:display:no_such_pref=foo"→ "Preference(s) … not found."python setup.py set-prefs <user> "browser:display:browser_tree_state_save_interval=5"→ savedpycodestyleclean on both filesPreferences.save()path unchanged)Summary by CodeRabbit