GeezerVison is showing github.com — Fix issue with Username being required for Shared server import config by KijongHan · Pull Request #9971 · pgadmin-org/pgadmin4
Conversation
KijongHan
commented
May 22, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 on Username being required even when Shared was set to true. This PR introduces more coherent constraint validation logic for shared servers so that you are required to either provide SharedUsername or Username (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 SharedUsername set, 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 underlying Username is not set)
Summary of changes
add separate Username constraint validation logic for shared servers when importing servers.json
add fallback to set Username to SharedUsername for shared servers so that the UX flow matches the manual UI creation flow for registering new shared servers
Summary by CodeRabbit
- Bug Fixes
- Improved import and validation of shared database servers: shared servers are now skipped for non-admin users, username requirements are enforced conditionally (allowing a shared-specific username when appropriate), and the effective credential used for imported servers is computed reliably. This yields more accurate configuration, fewer import errors, and improved security when handling shared server entries.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 <[email protected]>
…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 <[email protected]>
coderabbitai
Bot
commented
May 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a8598914-2de6-454b-9393-fa261071199b
📥 Commits
Reviewing files that changed from the base of the PR and between 034c8f2 and 62437ab.
📒 Files selected for processing (1)
web/pgadmin/utils/__init__.py
🚧 Files skipped from review as they are similar to previous changes (1)
- web/pgadmin/utils/init.py
Walkthrough
Validation 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.
Changes
Shared Server Configuration and Validation
| Layer / File(s) |
Summary |
Shared server validation logic web/pgadmin/utils/__init__.py |
validate_json_data derives is_shared from input and uses it to gate non-admin shared-server imports. When Service is absent it validates Port first, then enforces username requirements: non-shared servers must have Username; shared servers must have Username or SharedUsername. |
Load and apply computed server configuration web/pgadmin/utils/__init__.py |
load_database_servers computes is_shared and derives an effective username (falling back to SharedUsername when Username is missing for shared servers), then assigns new_server.username, new_server.shared, and new_server.shared_username from those computed values. |
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title accurately reflects the main change: fixing the issue where Username is required for shared server imports. |
| Linked Issues check |
✅ Passed |
The PR addresses #9226 by allowing SharedUsername or Username for shared servers and setting server.username to SharedUsername when Username is missing, with fallback using 'is None' check per reviewer feedback. |
| Out of Scope Changes check |
✅ Passed |
All changes in the PR are directly related to fixing the shared server import issue described in #9226; no out-of-scope modifications detected. |
| 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
Warning
Review ran into problems
🔥 Problems
Stopped 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 @coderabbit review after the pipeline has finished.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 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.json validation to accept either Username or SharedUsername for shared servers.
- Updated server import to populate
Server.username from SharedUsername when Username is not provided for shared servers.
- Minor refactor to reuse computed
is_shared during validation/import.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the careful analysis @KijongHan, and for not just rolling over to Copilot — your read on Username vs SharedUsername precedence matches the UI flow and is the right call. Username is the per-user override, SharedUsername is the group default, and Username winning when both are present is the correct semantics.
One ask before this lands: please change the fallback at line 739 from
if is_shared and not username:
username = shared_username
to
if is_shared and username is None:
username = shared_username
Reason: @hiteshjambhale's reproducer (Username: "" with SharedUsername absent) gets username = None after the fallback, and Server.username is nullable=False in the model. The current non-shared branch has the same latent issue with empty strings, but it's pre-existing — this PR widens the path on the shared branch, which the is None check closes without changing any other behaviour.
The broader question — should {"Username": ""} be valid input at all, given PostgreSQL won't authenticate with an empty username? — is worth a separate issue (and I'd argue the answer is no, validation should reject it for both shared and non-shared, parallel to the Service escape hatch). Happy to file that follow-up so this PR can stay scoped.
On the shared_username "purity" point: I agree with you — shared_username is the group default, it shouldn't silently inherit from a legacy Username field. Your handling there is correct.
|
KijongHan reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dpage
pushed a commit
that referenced
this pull request
Aug 18, 2026
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 master as 0ebefaf, squashed with you as the author; because the SHA changed GitHub will not close the PR itself, so I am doing that by hand.
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 {"Shared": true, "SharedUsername": null} and its empty-string equivalent are rejected instead of being accepted and then stored as the server's username. That was the same class of problem @hiteshjambhale spotted originally, just reached through the other key, and it is worth closing on the path this change widens. The pre-existing hole on the non-shared path, where {"Username": ""} is still accepted, is untouched and still wants the separate fix Ashesh described.
I added web/pgadmin/utils/tests/test_validate_json_data.py, which is the first coverage either of these functions has had: 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 section of docs/en_US/import_export_servers.rst still said Username was required in every server definition, so it now notes that a shared server may supply SharedUsername instead.
I left obj.get("Shared", None) as it was rather than defaulting it to False, incidentally. It looks like a tidy-up, but the dialog also stores NULL for a non-shared server, and add_value() would then start emitting "Shared": false into exported files, so it would trade one inconsistency for another.
Thanks also for pushing back on the Copilot review rather than just going along with it. Your reading of Username versus SharedUsername precedence was the right one.
|
KijongHan reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|