Skip to content

fix: guard 1097 distribution report procedures against division by zero - #145

Open
snehar-nd wants to merge 1 commit into
mainfrom
fix/1097-report-division-by-zero
Open

fix: guard 1097 distribution report procedures against division by zero#145
snehar-nd wants to merge 1 commit into
mainfrom
fix/1097-report-division-by-zero

Conversation

@snehar-nd

@snehar-nd snehar-nd commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

📋 Description

JIRA ID: AMM-2408

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)

ℹ️ Additional Information

Pr_1097AgegroupDistribution, Pr_1097GenderDistribution, Pr_1097LanguageDistribution and Pr_1097Sexualorientation each divide by v_totalcount (the count of matching beneficiary records) to compute ServiceProvidedRatio. When no records match the requested filters (date range / state / district / providerServiceMapID), v_totalcount is 0 and MySQL's strict sql_mode raises a division-by-zero error, which surfaces to the API/UI as "Data truncation: Division by 0" and aborts the whole report request (seen via Common-API's crmReports/getAllByGender and getAllBySexualOrientation).

Divide by NULLIF(v_totalcount,0) instead, so a zero total yields NULL (no error) which each procedure's existing null-to-zero handling already turns into a 0 ratio.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed reporting failures when no beneficiaries match the selected filters.
    • Reports now complete successfully and display zero-valued service ratios instead of producing division-by-zero errors.

Pr_1097AgegroupDistribution, Pr_1097GenderDistribution,
Pr_1097LanguageDistribution and Pr_1097Sexualorientation each divide by
v_totalcount (the count of matching beneficiary records) to compute
ServiceProvidedRatio. When no records match the requested filters
(date range / state / district / providerServiceMapID), v_totalcount is 0
and MySQL's strict sql_mode raises a division-by-zero error, which surfaces
to the API/UI as "Data truncation: Division by 0" and aborts the whole
report request (seen via Common-API's crmReports/getAllByGender and
getAllBySexualOrientation).

Divide by NULLIF(v_totalcount,0) instead, so a zero total yields NULL
(no error) which each procedure's existing null-to-zero handling already
turns into a 0 ratio.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
9.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dd58e051-4a16-4154-b1cb-11fc7dbb7b28

📥 Commits

Reviewing files that changed from the base of the PR and between cff8328 and c492bdc.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/dbreporting/V5__fix_1097_report_division_by_zero.sql

📝 Walkthrough

Walkthrough

The migration updates four 1097 reporting procedures to use NULLIF(v_totalcount,0) for service ratio calculations. Empty result sets therefore produce NULL, which existing post-processing converts to zero.

Changes

1097 reporting denominator handling

Layer / File(s) Summary
Guard report ratios against zero denominators
src/main/resources/db/migration/dbreporting/V5__fix_1097_report_division_by_zero.sql
Agegroup, gender, sexual orientation, and language report procedures avoid division by zero and preserve zero-valued output for empty match sets.

Estimated code review effort: 3 (Moderate) | ~20 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 clearly describes the main change: protecting 1097 distribution report procedures from division-by-zero errors.
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.

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.

@drtechie
drtechie requested a review from paras-dba July 28, 2026 14:38
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