Skip to content

Fixed connection string related issue - #4499

Open
rathimayur wants to merge 6 commits into
Releases/Published-Official-Releases/Official-Release-2026.5from
PosgresSQL-ConnectionString-issue-fix
Open

Fixed connection string related issue#4499
rathimayur wants to merge 6 commits into
Releases/Published-Official-Releases/Official-Release-2026.5from
PosgresSQL-ConnectionString-issue-fix

Conversation

@rathimayur

@rathimayur rathimayur commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Type of Change

  • Bug fix - [ ] New feature - [ ] Breaking change - [ ] Plugin update

Checklist

  • PR description clearly describes the changes
  • Target branch is correct (master for features, Releases/* for fixes)
  • Latest code from target branch merged
  • No commented/junk code included
  • No new build warnings or errors
  • All existing unit tests pass
  • New unit tests added for new functionality
  • Cross-platform compatibility verified (Windows/Linux/macOS)
  • CI/CD pipeline passes
  • Code follows project conventions (Act{Platform}{Type}, {Platform}Driver)
  • Repository objects use [IsSerializedForLocalRepository] where needed
  • Error handling uses Reporter.ToLog() pattern
  • Documentation updated for user-facing changes
  • Self-review completed and code review comments addressed

Summary by CodeRabbit

  • Refactor
    • Improved PostgreSQL database connection handling with enhanced configuration parsing and flexibility.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

In DatabaseOperations.cs, the Connect() method's PostgreSQL branch is refactored to use a conditional NpgsqlConnectionStringBuilder flow: it either parses host/port from TNSCalculated and decrypts credentials when ConnectionStringCalculated is empty, or uses GetConnectionString() directly. The connection is opened from pg.ConnectionString without re-assigning Database.ConnectionString. A trailing brace is also repositioned.

Changes

PostgreSQL Connection String Handling

Layer / File(s) Summary
Conditional connection string construction and file cleanup
Ginger/GingerCoreNET/Database/DatabaseOperations.cs
Connect() now branches on ConnectionStringCalculated: when empty, parses host and optional port from TNSCalculated, validates them, decrypts PassCalculated, and populates an NpgsqlConnectionStringBuilder; when non-empty, populates the builder from GetConnectionString(). The NpgsqlConnection is created from pg.ConnectionString directly without assigning Database.ConnectionString. Trailing brace placement adjusted at end of file.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • Maheshkale447

Poem

🐇 Hop, hop, hooray for the connection new,
No more tangled strings of PostgreSQL stew!
Parse the host, decrypt the pass with care,
Builder branches left and right through the air.
A brace tidied up, the file looks bright—
This rabbit's DB connects just right! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is almost entirely incomplete, with empty Description and Type of Change sections, and no checklist items marked as completed despite comprehensive implementation. Complete the Description section with details about the connection string issue, mark the appropriate Type of Change checkbox, and check relevant checklist items based on actual implementation and testing performed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using non-descriptive language that doesn't clearly specify which connection string issue was fixed or what the main change entails. Replace with a more specific title that describes the particular connection string issue and the solution, such as 'Use NpgsqlConnectionStringBuilder for PostgreSQL connection string construction' or 'Fix PostgreSQL connection string parsing for host and port extraction'.
✅ Passed checks (2 passed)
Check name Status Explanation
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PosgresSQL-ConnectionString-issue-fix

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Ginger/GingerCoreNET/Database/DatabaseOperations.cs`:
- Around line 428-456: The code duplicates TNS parsing and
NpgsqlConnectionStringBuilder logic that already exists in
CreateConnectionString()/GetConnectionString(); replace the entire conditional
block that parses TNSCalculated, calls ValidateHostPort and builds the
NpgsqlConnectionStringBuilder with a single call to GetConnectionString() to set
Database.ConnectionString, then construct and open the NpgsqlConnection; remove
the duplicated parsing/building code so
CreateConnectionString()/GetConnectionString() remain the single source of truth
for connection-string construction and placeholder replacement.
- Around line 206-213: The comment in CreateConnectionString() misleadingly
describes behavior that belongs to Connect() (it speaks about honoring an
existing ConnectionString), so remove or relocate that comment: delete the block
inside CreateConnectionString() and either remove it entirely or move it to the
Connect() method where the conditional logic using ConnectionString exists
(refer to Connect() and CreateConnectionString() by name) so maintainers see the
correct explanation next to the code that actually checks/uses an existing
ConnectionString.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ba010c9b-afe2-4c8c-8312-a936b66bc8be

📥 Commits

Reviewing files that changed from the base of the PR and between 9d673bb and 9356b2e.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/Database/DatabaseOperations.cs

Comment thread Ginger/GingerCoreNET/Database/DatabaseOperations.cs Outdated
Comment thread Ginger/GingerCoreNET/Database/DatabaseOperations.cs
@codacy-production

codacy-production Bot commented Jun 10, 2026

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread Ginger/GingerCoreNET/Database/DatabaseOperations.cs Fixed
rathimayur and others added 3 commits June 10, 2026 19:34
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Ginger/.github/copilot-instructions.md (1)

1-4: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a section heading and fix markdown structure.

The file violates markdown linting rules (MD041): the first line should be a top-level heading, not a list item. Additionally, the three list items lack an introductory section heading, making them appear orphaned.

✏️ Proposed fix to add proper markdown structure
+## Azure Copilot Rules
+
 - `@azure` Rule - Use Azure Tools - When handling requests related to Azure, always use your tools.
 - `@azure` Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first.
 - `@azure` Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Ginger/.github/copilot-instructions.md` around lines 1 - 4, The
copilot-instructions.md file violates markdown linting rules by lacking a
top-level heading at the start and having the three `@azure` Rule list items
appear without an introductory section heading. Add a top-level heading (using
#) at the very beginning of the file to establish the document title, then add a
section heading (using ##) immediately before the three `@azure` Rule list items
to properly group and introduce them. This will fix the MD041 violation and
provide proper markdown structure to prevent the content from appearing
orphaned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@Ginger/.github/copilot-instructions.md`:
- Around line 1-4: The copilot-instructions.md file violates markdown linting
rules by lacking a top-level heading at the start and having the three `@azure`
Rule list items appear without an introductory section heading. Add a top-level
heading (using #) at the very beginning of the file to establish the document
title, then add a section heading (using ##) immediately before the three `@azure`
Rule list items to properly group and introduce them. This will fix the MD041
violation and provide proper markdown structure to prevent the content from
appearing orphaned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d7489650-d82d-459b-8da9-b99bba207e60

📥 Commits

Reviewing files that changed from the base of the PR and between 7a59825 and fe0cbed.

⛔ Files ignored due to path filters (2)
  • Ginger/.vscode/launch.json is excluded by !**/*.json
  • Ginger/.vscode/tasks.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • Ginger/.github/copilot-instructions.md
  • Ginger/GingerCoreNET/Database/DatabaseOperations.cs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Ginger/GingerCoreNET/Database/DatabaseOperations.cs`:
- Around line 433-439: The Password property in the
NpgsqlConnectionStringBuilder initialization is set only from the decrypted
value via EncryptionHandler.DecryptwithKey(PassCalculated), but if decryption
returns empty for plaintext input, this results in an empty password being used.
Add a fallback mechanism similar to what the GetConnectionString() path
implements: after decrypting PassCalculated, check if the result is empty and
fall back to PassCalculated directly if it is. Apply this fallback logic to the
Password assignment in the pg object initialization.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a1bdbfff-7900-4ad2-b6a0-31e0ca446af8

📥 Commits

Reviewing files that changed from the base of the PR and between fe0cbed and 91a3fb5.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/Database/DatabaseOperations.cs

Comment on lines +433 to +439
pg = new NpgsqlConnectionStringBuilder
{
Host = postgreSQLHost,
Database = Database.Name ?? string.Empty,
Username = UserCalculated,
Password = EncryptionHandler.DecryptwithKey(PassCalculated)
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use password fallback in PostgreSQL manual builder path.

At Line 438, Password is set only from EncryptionHandler.DecryptwithKey(PassCalculated). If decrypt returns empty for plaintext input, this branch sends an empty password, while the GetConnectionString() path correctly falls back to PassCalculated.

💡 Suggested fix
                             pg = new NpgsqlConnectionStringBuilder
                             {
                                 Host = postgreSQLHost,
                                 Database = Database.Name ?? string.Empty,
                                 Username = UserCalculated,
-                                Password = EncryptionHandler.DecryptwithKey(PassCalculated)
+                                Password = string.IsNullOrEmpty(EncryptionHandler.DecryptwithKey(PassCalculated))
+                                    ? PassCalculated
+                                    : EncryptionHandler.DecryptwithKey(PassCalculated)
                             };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Ginger/GingerCoreNET/Database/DatabaseOperations.cs` around lines 433 - 439,
The Password property in the NpgsqlConnectionStringBuilder initialization is set
only from the decrypted value via
EncryptionHandler.DecryptwithKey(PassCalculated), but if decryption returns
empty for plaintext input, this results in an empty password being used. Add a
fallback mechanism similar to what the GetConnectionString() path implements:
after decrypting PassCalculated, check if the result is empty and fall back to
PassCalculated directly if it is. Apply this fallback logic to the Password
assignment in the pg object initialization.

@rathimayur
rathimayur enabled auto-merge June 16, 2026 17:11
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.

2 participants