Skip to content

Fix key manager deletion blocked when linked to applications (#3164) - #3181

Open
lahiruudayakumara wants to merge 1 commit into
wso2:mainfrom
lahiruudayakumara:fix/3164-key-manager-deletion
Open

Fix key manager deletion blocked when linked to applications (#3164)#3181
lahiruudayakumara wants to merge 1 commit into
wso2:mainfrom
lahiruudayakumara:fix/3164-key-manager-deletion

Conversation

@lahiruudayakumara

Copy link
Copy Markdown
Contributor

Purpose

When attempting to delete a Key Manager that has linked application OAuth client ID mappings (app_key_mappings), the operation failed due to a database foreign key constraint error (SQLITE_CONSTRAINT_FOREIGNKEY). This PR ensures linked application key mappings are cleaned up before removing the key manager record.

Resolves #3164

Goals

  • Allow administrators to delete a Key Manager without being blocked by foreign key constraints from linked applications.
  • Ensure key manager deletion and client mapping cleanup execute atomically within a single database transaction.

Approach

  • DAO Layer (keyManagerDao.js): Updated deleteKm to accept a transaction handle and delete dependent rows from app_key_mappings (WHERE km_uuid = ?) before deleting the row from key_managers.
  • Service Layer (keyManagerService.js): Wrapped kmDao.delete inside db.withTransaction to guarantee atomicity.
  • Tests:
    • Added unit test in src/dao/keyManagerDao.test.js to verify query execution order.
    • Added REST API integration test in it/rest-api/key-managers/key-managers.spec.js asserting successful deletion (HTTP 204) of a Key Manager linked to an application.

User stories

As an API Portal administrator, I can delete a Key Manager even when applications have registered client IDs against it, without encountering database foreign key errors.

Documentation

N/A - Bug fix addressing internal cascading delete logic. No changes to user documentation or public API contracts.

Automation tests

  • Unit tests

    Added unit test in src/dao/keyManagerDao.test.js testing deleteKm query execution sequence (app_key_mappings cleanup followed by key_managers delete).

  • Integration tests

    Added test case in it/rest-api/key-managers/key-managers.spec.js verifying end-to-end deletion of a Key Manager linked to consumer keys/applications.

Security checks

Samples

N/A

Related PRs

N/A

Test environment

  • Node.js: 24.6.0
  • OS: macOS (ARM64)
  • Database: SQLite

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@lahiruudayakumara, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9481f942-9925-4c95-aa07-37e7b0a43700

📥 Commits

Reviewing files that changed from the base of the PR and between 2613ad3 and a83e3fb.

📒 Files selected for processing (4)
  • portals/api-portal/it/rest-api/key-managers/key-managers.spec.js
  • portals/api-portal/src/dao/keyManagerDao.js
  • portals/api-portal/src/dao/keyManagerDao.test.js
  • portals/api-portal/src/services/keyManagerService.js

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.

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.

[Bug]: Key Manager deletion is blocked when linked to applications by adding client ID

1 participant