Repository navigation
Conversation
validate_json_data required Username for all non-Service connections, rejecting legitimate JSON that only carried SharedUsername. Accept either attribute when Shared is true; keep Username required for non-shared servers. Extract is_shared as a local while we're here — it's now referenced twice in the loop body. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…d servers When loading database servers from an import file, fall back to SharedUsername for the underlying server.username when the server is shared and no explicit Username is provided. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughValidation and loader functions in web/pgadmin/utils/init.py now derive an is_shared flag from input and compute an effective username (using SharedUsername when appropriate). Validation enforces username requirements conditionally for shared vs non-shared servers; the loader applies computed shared and username values to the server objects. ChangesShared Server Configuration and Validation
🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a 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.
Pull request overview
This PR updates pgAdmin’s servers.json import path to correctly handle shared servers by loosening validation so shared server definitions can provide SharedUsername instead of always requiring Username, and by applying a fallback so imported shared servers have an effective username consistent with the UI flow.
Changes:
- Adjusted
servers.jsonvalidation to accept eitherUsernameorSharedUsernamefor shared servers. - Updated server import to populate
Server.usernamefromSharedUsernamewhenUsernameis not provided for shared servers. - Minor refactor to reuse computed
is_sharedduring validation/import.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the careful analysis @KijongHan, and for not just rolling over to Copilot — your read on One ask before this lands: please change the fallback at line 739 from if is_shared and not username:
username = shared_usernameto if is_shared and username is None:
username = shared_usernameReason: @hiteshjambhale's reproducer ( The broader question — should On the |
|
thanks so much for your reviews @asheshv @hiteshjambhale and appreciate the followup to some of the questions I've posed. Have addressed your suggested changes. |
|
hi @hiteshjambhale @asheshv Checking to see if you had a chance to rereview my changes that addresses your PR feedback/concerns? Keen to get these changes in! |
Importing a servers.json definition insisted on a Username attribute for
every server, so a shared server that carried only SharedUsername was
rejected with "'Username' attribute not found for server ...", even though
the dialog treats SharedUsername as the default username for a shared
server. Validation now accepts either attribute when the server is shared,
whilst non-shared servers still require Username.
The loader derives the username it stores in the same way. Username wins
when both are present, since it is the owner's own login and the per-user
override, and SharedUsername is used when Username is absent. That matches
what creating a shared server through the dialog produces, so an imported
shared server prompts for a password on the first connection rather than
sitting on a loading spinner with no username to connect with.
SharedUsername itself does not inherit a legacy Username, because it means
"the default username for the other users of this server" rather than a
fallback for the owner.
Folded in during review:
Validation now looks at the values rather than merely at the keys. Checking
for the presence of a key alone let {"Shared": true, "SharedUsername": null}
and its empty-string equivalent through, and the loader would then store
that as the server's username: on a schema created from the model that is an
integrity error surfaced as a raw "Error creating server" string, whilst on
a database migrated over the years, where the column carries no NOT NULL, it
imports silently and leaves behind a server that cannot connect. The
equivalent pre-existing hole on the non-shared path, where {"Username": ""}
is still accepted, is left for a separate change covering empty usernames in
general.
Tests in web/pgadmin/utils/tests/test_validate_json_data.py cover the
username requirements for shared and non-shared servers, the Service escape
hatch, the integer port check, and shared servers being skipped rather than
rejected for a non-admin user. The JSON format documentation notes that
SharedUsername may stand in for Username.
Fixes #9226
|
Thanks Thomas, and apologies for the wait. This has landed on I folded three things in whilst merging, all of them small: The shared branch of the validation now tests the values rather than merely the presence of the keys, so I added The JSON format section of I left Thanks also for pushing back on the Copilot review rather than just going along with it. Your reading of |
|
For the record, the follow-up on the non-shared path is now filed as #10309, with @hiteshjambhale's original reproducer and a note on why an empty username fails so obscurely (libpq substitutes the OS account, so the error names a user that appears nowhere in the imported configuration). |
Resolves #9226
What does this PR do?
This PR resolves
Username attribute not found for server 'shared_server'errors where server json import validation logic had a hard constraint onUsernamebeing required even whenSharedwas set to true. This PR introduces more coherent constraint validation logic for shared servers so that you are required to either provideSharedUsernameorUsername(for backwards compatibility). Furthermore, the underlying data model 'Username' property is set to 'SharedUsername' (for shared servers only) to align with UI behaviour for setting this fallback.The UX also feels better as when after registering shared servers with only the
SharedUsernameset, when trying to connect to the server for the first time it prompts for the password (instead of showing an infinite loading spinner because the underlyingUsernameis not set)Summary of changes
add separate
Usernameconstraint validation logic for shared servers when importingservers.jsonadd fallback to set
UsernametoSharedUsernamefor shared servers so that the UX flow matches the manual UI creation flow for registering new shared serversSummary by CodeRabbit