Skip to content

Fix issue with Username being required for Shared server import config#9971

Open
KijongHan wants to merge 2 commits into
pgadmin-org:masterfrom
KijongHan:GH_9226
Open

Fix issue with Username being required for Shared server import config#9971
KijongHan wants to merge 2 commits into
pgadmin-org:masterfrom
KijongHan:GH_9226

Conversation

@KijongHan
Copy link
Copy Markdown
Contributor

@KijongHan KijongHan commented May 22, 2026

Resolves issue #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 handling of shared database server imports with enhanced validation logic. Credential requirements for shared servers are now properly managed based on user permissions, ensuring accurate configuration and better security.

Review Change Stack

KijongHan and others added 2 commits May 23, 2026 09:43
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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

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: cb7346d7-1337-4d82-8c23-496ed75c8c30

📥 Commits

Reviewing files that changed from the base of the PR and between 533aed1 and 177b57d.

📒 Files selected for processing (1)
  • web/pgadmin/utils/__init__.py

Walkthrough

Changes to server import validation and loading logic in web/pgadmin/utils/__init__.py. Two functions now use computed is_shared and username values to coordinate shared server configuration: validation enforces conditional username requirements based on shared status, and loading applies the computed values when populating 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. In the validation path where Service is unavailable, Port is validated first, then username requirements are enforced conditionally: non-shared servers must have Username, while shared servers must have Username or SharedUsername.
Load and apply computed server configuration
web/pgadmin/utils/__init__.py
load_database_servers determines is_shared and computes effective username (falling back to SharedUsername for shared servers when Username is absent), then assigns these computed values to new_server.username and new_server.shared instead of reading directly from the JSON object.

🎯 2 (Simple) | ⏱️ ~12 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 directly and accurately summarizes the main change: fixing validation logic for shared server imports to accept SharedUsername or Username instead of requiring Username unconditionally.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

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.

1 participant