Skip to content

RG-T129 Delete Repo bug - #449

Merged
ucswift merged 1 commit into
masterfrom
develop
Aug 7, 2026
Merged

RG-T129 Delete Repo bug#449
ucswift merged 1 commit into
masterfrom
develop

Conversation

@ucswift

@ucswift ucswift commented Aug 7, 2026

Copy link
Copy Markdown
Member

Pull Request Description: RG-T129 Delete Repo bug

Summary

This PR fixes multiple bugs in the department deletion repository that prevented departments from being properly deleted in SQL Server environments.

Changes

File: Repositories/Resgrid.Repositories.DataRepository/DeleteRepository.cs

Three critical fixes were applied to the DeleteDepartmentAndUsersAsync method:

  1. Transaction parameter missing — The SQL delete operations were not being executed within the transaction. The transaction object was created but never passed to db.ExecuteAsync(), meaning the delete commands ran outside the transaction scope (or failed silently).

  2. Connection not opened before transaction — Added an explicit await db.OpenAsync() call before BeginTransaction() to ensure the connection is in an open state prior to creating the transaction.

  3. Incorrect return value — The method always returned false even after a successful deletion. This was corrected to return true upon successful completion of the SQL Server deletion block.

Functional Impact

Prior to this fix, deleting a department and its associated users would not work correctly on SQL Server deployments — the delete operations were effectively non-functional due to the missing transaction binding, and the method incorrectly reported failure regardless of outcome. Departments and their related data (users, messages, etc.) will now be properly and reliably deleted within a transactional context.

@Resgrid-Bot

Resgrid-Bot commented Aug 7, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@request-info

request-info Bot commented Aug 7, 2026

Copy link
Copy Markdown

Thanks for opening this, but we'd appreciate a little more information. Could you update it with more details?

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DeleteDepartmentAndUsersAsync now explicitly opens a SqlConnection, executes deletion within its transaction, and returns true after a successful commit.

Changes

Department deletion

Layer / File(s) Summary
SQL Server deletion transaction
Repositories/Resgrid.Repositories.DataRepository/DeleteRepository.cs
The method uses SqlConnection, opens it asynchronously, passes the active transaction to the deletion command, and returns true after commit.

Estimated code review effort: 2 (Simple) | ~10 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.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title identifies the delete repository bug addressed by the pull request.
✨ 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 develop

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.

using (IDbConnection db = new SqlConnection(DataConfig.CoreConnectionString))
using (var db = new SqlConnection(DataConfig.CoreConnectionString))
{
await db.OpenAsync();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

Unguarded db.OpenAsync() call risks throwing an unhandled exception upon a database connection failure. Wrap OpenAsync and the subsequent transaction/ExecuteAsync block in a try/catch that logs context and handles or rethrows the error appropriately to comply with Rule [1].

Kody rule violation: Handle async operations with proper error handling

Prompt for LLM

File Repositories/Resgrid.Repositories.DataRepository/DeleteRepository.cs:

Line 29:

Unguarded `db.OpenAsync()` call risks throwing an unhandled exception upon a database connection failure. Wrap `OpenAsync` and the subsequent transaction/`ExecuteAsync` block in a try/catch that logs context and handles or rethrows the error appropriately to comply with Rule [1].

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

using (IDbConnection db = new SqlConnection(DataConfig.CoreConnectionString))
using (var db = new SqlConnection(DataConfig.CoreConnectionString))
{
await db.OpenAsync();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

Unguarded external database call in db.OpenAsync() omits mandated error mapping per Rule [27]. Wrap the OpenAsync call in a try/catch, log the relevant departmentId identifier, and map exceptions to an application-level error or rethrow with context.

Kody rule violation: Add try-catch blocks for external calls

Prompt for LLM

File Repositories/Resgrid.Repositories.DataRepository/DeleteRepository.cs:

Line 29:

Unguarded external database call in `db.OpenAsync()` omits mandated error mapping per Rule [27]. Wrap the `OpenAsync` call in a try/catch, log the relevant `departmentId` identifier, and map exceptions to an application-level error or rethrow with context.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

@ucswift

ucswift commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Approve

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR is approved.

@ucswift
ucswift merged commit 8d369c8 into master Aug 7, 2026
18 of 19 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2026
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