Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

FINERACT-3378: Fix seeded reports that differ on PostgreSQL - #7199

Open
Abhishek6122008 wants to merge 1 commit into
apache:developfrom
Abhishek6122008:feature/FINERACT-3378-report-sql-differences
Open

Abhishek6122008 wants to merge 1 commit into
apache:developfrom
Abhishek6122008:feature/FINERACT-3378-report-sql-differences

Conversation

@Abhishek6122008

@Abhishek6122008 Abhishek6122008 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

https://issues.apache.org/jira/browse/FINERACT-3378

Seeded reports that returned different results on PostgreSQL than on MySQL/MariaDB for the same data. One commit per sub-task, all in 0297_fix_report_sql_differences_between_databases.xml. Small fixes replace only the part that differs, so a report a bank has edited is left alone when its text no longer matches.

Sub-task Report(s) Fix
FINERACT-3396 Active Loans - Summary coalesce(laa.loan_id, l.id, NULL) counted every active loan as in arrears; now CASE WHEN laa.loan_id IS NOT NULL THEN l.id END. Two labels lose their runs of spaces.
FINERACT-3397 Loan fully repaid Grouped per repayment installment (385 rows vs 91); now per loan, with the last installment's due date. The MySQL version takes the same values instead of an arbitrary row (which also fails under MySQL 8's ONLY_FULL_GROUP_BY).
FINERACT-3398 Dormant Prospects DATE_PART('MONTH', AGE(...)) is 0-11; now years * 12 + months, like TIMESTAMPDIFF(MONTH, ...).
FINERACT-3399 GeneralLedgerReport Table Outer SELECT gets account_name; system entries get 0system like MySQL.
FINERACT-3400 TxnRunningBalances Adds the missing Amount column. Outstanding Principal, Interest Income and Principal Write Off were per-transaction amounts; they are now running totals (window sums in date, id order) from the opening balance.
FINERACT-3401 8 loan reports DATE_TRUNC('day', x) returned timestamps; now CAST(x AS DATE).
FINERACT-3402 ClientTrendsByWeek, LoanTrendsByWeek MySQL now uses ISO weeks (WEEK(x, 3), same as PostgreSQL's EXTRACT(WEEK ...) for every day 2018-2030), and both sort by week.

How it was checked:

  • Each report run through the API on Fineract (develop) on MariaDB and on a PostgreSQL copy of the same data (reconciled column by column): every report above now returns the same rows and values. Planted arrears rows confirmed the arrears count; the month count matches TIMESTAMPDIFF for every day from 2020 against four end dates (month ends, a leap day).
  • TxnRunningBalances: same opening row, same transactions and same final totals on both for three date ranges. Row by row the running totals can't match MariaDB: the MySQL version relies on ORDER BY inside a derived table, which MariaDB ignores, so its totals accumulate in no particular order. Not changed here.
  • StretchyReportsSmokeTest gets tests for 3396, 3399, 3400, 3401 and 3402 (Loan fully repaid and Dormant Prospects need data the setup can't create). Built this branch and ran the smoke test against fresh PostgreSQL and MariaDB databases: 49/49 on both. CI covers MySQL.

Not in this PR: GeneralLedgerReport Table's opening balance differs too, because both versions use a date condition that isn't an opening balance (MySQL >= start - 2 days, PostgreSQL <= start - 3 days). Choosing the right rule changes both, so I'll raise it on FINERACT-3399 first. Related: #7196 (FINERACT-3377, NOW() in report SQL).

Checklist

  • 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.
  • If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately.
  • I followed the AI Policy.

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

Seeded reports returned different results on PostgreSQL than on MySQL/MariaDB for the same data:

- FINERACT-3396: Active Loans - Summary counted every active loan as in arrears
  (coalesce(laa.loan_id, l.id, NULL)); two labels had runs of spaces.
- FINERACT-3397: Loan fully repaid returned one row per installment; now one per loan with the last
  installment's due date, on both databases (also fixes MySQL 8's ONLY_FULL_GROUP_BY).
- FINERACT-3398: Dormant Prospects counted only the months part of the age (0 to 11).
- FINERACT-3399: GeneralLedgerReport Table had no account_name column, and 'system' instead of '0system'.
- FINERACT-3400: TxnRunningBalances had no Amount column and no running totals; now window sums from the
  opening balance.
- FINERACT-3401: eight reports returned timestamps (DATE_TRUNC('day', x)) instead of dates.
- FINERACT-3402: the weekly trends reports use ISO weeks on both databases and sort by week.

Tests for 3396, 3399, 3400, 3401 and 3402 in StretchyReportsSmokeTest.
@Abhishek6122008
Abhishek6122008 force-pushed the feature/FINERACT-3378-report-sql-differences branch from feea872 to 694b1be Compare December 6, 2026 01:49
@Abhishek6122008

Copy link
Copy Markdown
Contributor Author

Could someone rerun the failed E2E Shard 12 job? The runner crashed ("lost communication with the server"), so it isn't a test failure.

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