Skip to content

FINERACT-2653: Fix provisioning category delete failing with mandatory categoryname error#6011

Open
oluexpert99 wants to merge 1 commit into
apache:developfrom
TECHSERVICES-LIMITED:bugfix/FINERACT-2653
Open

FINERACT-2653: Fix provisioning category delete failing with mandatory categoryname error#6011
oluexpert99 wants to merge 1 commit into
apache:developfrom
TECHSERVICES-LIMITED:bugfix/FINERACT-2653

Conversation

@oluexpert99

@oluexpert99 oluexpert99 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Fix provisioning category delete failing with mandatory category name error

  • Load the category by command.entityId() instead of running create-validation on the body-less DELETE.
  • Drop ProvisioningCategory.fromJson(command), which left the @id null so the in-use check and repository.delete() targeted a transient entity and never removed the row.
  • Throw ProvisioningCategoryNotFoundException for an unknown id.
  • Add ProvisioningCategoryWritePlatformServiceJpaRepositoryImplTest covering delete-success, not-found, and in-use-cannot-delete, asserting create-validation is never invoked on delete.

Description

Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our coding conventions.
  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Your assigned reviewer(s) will follow our guidelines for code reviews.

@oluexpert99 oluexpert99 force-pushed the bugfix/FINERACT-2653 branch from 2f31c63 to 542f574 Compare June 21, 2026 21:15
@oluexpert99 oluexpert99 changed the title FINERACT-2653: Fix provisioning category delete failing with mandator… FINERACT-2653 Jun 21, 2026
@oluexpert99 oluexpert99 changed the title FINERACT-2653 FINERACT-2653: Fix provisioning category delete failing with mandatory categoryname error Jun 21, 2026
final String sql = "select (CASE WHEN (exists (select 1 from m_loanproduct_provisioning_details lpd where lpd.category_id = ?)) = 1 THEN 'true' ELSE 'false' END)";
final String isLoansUsingCharge = this.jdbcTemplate.queryForObject(sql, String.class, new Object[] { categoryID });
return Boolean.valueOf(isLoansUsingCharge);
private boolean isAnyLoanProductsAssociateWithThisProvisioningCategory(final Long categoryId) {

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.

private boolean isAnyLoanProductsAssociateWithThisProvisioningCategory(final Long categoryId) {
    // The category is in use when a provisioning criteria definition references it. Querying the
    // m_loanproduct_provisioning_details table was incorrect because category_id belongs to
    // m_provisioning_criteria_definition. EXISTS is portable across PostgreSQL, MySQL and MariaDB,
    // and avoids counting all matching rows.
    final String sql = """
            select exists (
                select 1
                from m_provisioning_criteria_definition
                where category_id = ?
            )
            """;

    final Boolean exists = this.jdbcTemplate.queryForObject(sql, Boolean.class, categoryId);
    return Boolean.TRUE.equals(exists);
}

Might be even better, no? Can you please look into it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @adamsaghy . This has been updated

@oluexpert99 oluexpert99 force-pushed the bugfix/FINERACT-2653 branch from 542f574 to cd382c6 Compare June 22, 2026 10:35
@oluexpert99 oluexpert99 requested a review from adamsaghy June 22, 2026 10:38
@adamsaghy

Copy link
Copy Markdown
Contributor

@oluexpert99 Please review the failing checks.

@oluexpert99 oluexpert99 reopened this Jun 22, 2026
@oluexpert99

Copy link
Copy Markdown
Contributor Author

Hi @adamsaghy . does not look like a check failure

…y categoryname error

- Load the category by command.entityId() instead of running create-validation on the body-less DELETE.
- Drop ProvisioningCategory.fromJson(command), which left the @id null so the in-use check and
  repository.delete() targeted a transient entity and never removed the row.
- Throw ProvisioningCategoryNotFoundException for an unknown id.
- Fix the in-use check: it queried the non-existent m_loanproduct_provisioning_details table (failed on
  every database); query m_provisioning_criteria_definition (where category_id actually lives) with a
  portable EXISTS that short-circuits at the first match and maps to Boolean across PostgreSQL and
  MySQL/MariaDB, instead of the MySQL-only "(exists(...)) = 1".
- Add ProvisioningCategoryWritePlatformServiceJpaRepositoryImplTest covering delete-success,
  not-found, and in-use-cannot-delete, asserting create-validation is never invoked on delete.

Signed-off-by: oluexpert99 <farooq@techservicehub.io>
@oluexpert99 oluexpert99 force-pushed the bugfix/FINERACT-2653 branch from cd382c6 to 4857654 Compare June 22, 2026 17:51
@oluexpert99

Copy link
Copy Markdown
Contributor Author

@adamsaghy . checks passed

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