Fix regression introduced by Apply-to-Oldest optimization - #10227
Conversation
|
Nice solution dcenic, the same-sign-first ordering is elegant. I re-traced it against the scenarios behind #9881 and I agree it restores the correct sign decision while keeping the optimization: the sum cannot cross zero inside the same-sign block, and once it strictly crosses in the opposite-sign block, every remaining entry only pushes it further the same way, so the truncated decision matches the full one. The One residual population worth a thought for the ICM, since it survives any early exit whose proof relies on an entry's Happy to see the tests carried over. I'll close #9881 in favor of this PR once it merges. |
|
Franco111000 Thanks, as for the concern about the corrupt remaining amounts that may have already been caused by the regression - we have no way of fixing that with a code fix. Customers will need to un-apply the erroneously applied entries, then re-apply them with the fixed 'Apply-to-Oldest' strategy. |
|
I dug deeper to make sure my earlier concern was concrete rather than theoretical. It is, with a happy ending: your remediation guidance covers it. On 28.2 the truncated sum can land on exactly zero, the Two good things follow. Your One minor note: Still looks good to me overall, closing #9881 once this merges. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
Agentic PR Review - Round 2Recommendation: AcceptWhat this PR doesThe new commits since round 1 clean up the analyzer issues from the added tests and add exact-offset coverage for vendor and employee Apply-to-Oldest scenarios. The full PR still fixes the posting regression by weighing same-sign entries first, using a strict Status of previous suggestions
New observations (commits since round 1)None - the new commits address the prior validation findings and add boundary coverage. Risk assessment and necessityRisk: This remains a high-sensitivity posting and data-integrity path in codeunit 12 across customer, vendor, and employee application logic. The change does not alter public signatures, and the current PR checks are green. The new tests reduce the main regression risk by covering both the reported same-sign failure and the exact-offset boundary for the optimized loop. Necessity: The change is required because normal Apply-to-Oldest posting can otherwise close the wrong ledger entries without an error. The scope is right for the bug: it fixes the shared customer, vendor, and employee pattern while keeping the performance optimization and adding regression coverage.
|
…10227) <!-- Thanks for contributing to BCApps! A few things before you hit "Create pull request": - Your PR must link to an approved issue. New here? See CONTRIBUTING.md. - You must have built and run your change yourself. CI is a safety net, not a substitute. - If you used AI or an agent to write this PR, you are still the author. Read the diff, build it, and try it before requesting review. Contributing guide: https://github.com/microsoft/BCApps/blob/main/CONTRIBUTING.md Local dev environment: https://github.com/microsoft/BCApps/blob/main/LOCAL_DEV_ENV.md --> ## What & why Fix regression introduced by Apply-to-Oldest optimization. Detailed explanation of the regression is in microsoft#9529 ## Linked work <!-- Required: link an approved GitHub issue using "Fixes #<number>". Microsoft contributors: also link the ADO work item with "AB#<number>" if you have one. --> Fixes [AB#646691](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/646691) and its GitHub counterpart microsoft#9529 ## How I validated this - [X] I read the full diff and it contains only changes I intended. - [X] I built the affected app(s) locally with no new analyzer warnings. - [ ] I ran the change in Business Central and confirmed it behaves as expected. - [X] I added or updated tests for the new behavior, or explained below why none are needed. **What I tested and the outcome** *(required — be specific: scenarios, commands, screenshots for UI changes)* Added new automated tests: - 4 tests that guard against the regression added by the partner, taken from this PR microsoft#9881 - - one extra tests that confirms the performance optimization works (that early exit is done when summing is sufficient) - <!-- Example: - Ran the new "Post and Send" action on a sales invoice in a fresh container; document posted and email queued (see screenshot). - New unit tests in MyFeatureTest.Codeunit.al pass locally; full module test suite green. - No tests added because change is comment-only / refactor with existing coverage. --> ## Risk & compatibility There is test coverage for both the regression and the performance optimization, so the risk is low. <!-- Anything reviewers should watch for: breaking changes, upgrade/data impact, permissions, telemetry, feature flags, follow-up work. Write "None" if there's nothing to call out. -->
|
Franco111000 This is being backported to 28.2 and higher release branches too. That means it will be deployed to live customers within the next 10-12 days. |
|
Great news, thanks for carrying it through to the release branches, that closes the loop on the 28.2 regression for live tenants. Pleasure collaborating on this one. |
What & why
Fix regression introduced by Apply-to-Oldest optimization. Detailed explanation of the regression is in #9529
Linked work
Fixes AB#646691 and its GitHub counterpart #9529
How I validated this
What I tested and the outcome (required — be specific: scenarios, commands, screenshots for UI changes)
Added new automated tests:
Risk & compatibility
There is test coverage for both the regression and the performance optimization, so the risk is low.