Anonymous | Login
Project:
RSS
  
News | My View | View Issues | Roadmap | Summary

View Issue DetailsJump to Notes ] Issue History ] Print ]
ID
0045428
TypeCategorySeverityReproducibilityDate SubmittedLast Update
defect[Localization Pack: Spain] SIImajorhave not tried2020-11-11 18:022020-11-25 00:01
ReportershuehnerView Statuspublic 
Assigned ToMery Anelo 
PrioritynormalResolutionopenFixed in Version
StatusscheduledFix in branchFixed in SCM revision
ProjectionnoneETAnoneTarget Version
OSAnyDatabaseAnyJava version
OS VersionDatabase versionAnt version
Product VersionSCM revision 
Regression date
Regression introduced by commit
Regression level
Review Assigned To
Regression introduced in release
Summary

0045428: FacturasEventHandler -> SIIUtils.getLegalOrganization has setAdminMode but never calls restorePreviousMode

DescriptionFound via many Junit tests from backoffice failing with

Test case should take care of reseting admin mode correctly in a finally block, use OBContext.restorePreviousMode

when having org.openbravo.module.sii template installed.

For example
org.openbravo.test.costing.TestCostingSourceAdjustments.testCostingAAA
(around 60-70 in total)

Debugging this points to SIIUtils.getLegalOrganization utility Function called via FacturasEventHandler

    at org.openbravo.dal.core.OBContext.addStackTrace(OBContext.java:362)
    at org.openbravo.dal.core.OBContext.setAdminMode(OBContext.java:223)
    at org.openbravo.module.sii.utils.SIIUtils.getLegalOrganization(SIIUtils.java:308)
    at org.openbravo.module.sii.eventhandlers.FacturasEventHandler.checkInvoice(FacturasEventHandler.java:116)
    at org.openbravo.module.sii.eventhandlers.FacturasEventHandler.onUpdate(FacturasEventHandler.java:68)

Reviewing that function shows it uses setAdminMode but does never restorePreviousMode violating calling convention to always use those in pairs (typically with a finally block)



Steps To ReproduceFound in specific customer instance but probably following is enough:

a.) Backoffice environment (testing in release/20Q4 branch)
b.) Add sii module
c.) run junit tests.
c.1) For example the following tests showcases the problem:
org.openbravo.test.createlinesfrom.CreateLinesFromTest
Proposed SolutionReview code and fix calling convention for adminMode by using the typical recommended pattern.

OBContext.setAdminMode(bool)
try {
  <code running with adminMode>
} finally {
  OBContext.restorePreviousMode();
}
TagsNo tags attached.
Attached Filesdiff file icon 45428.diff [^] (676 bytes) 2020-11-11 18:47 [Show Content]

- Relationships Relation Graph ] Dependency Graph ]
related to defect 0045429 closedshuehner Openbravo ERP Code to detect+warn about Unbalanced adminMode in OBBaseTest should be improved 

-  Notes
(0124284)
shuehner (administrator)
2020-11-11 18:03

Note: Quick check on that SIIUtils.java class shows the same issue being present not just in this utility function but also in many others.

So apart from fixing this specific case probably the whole file (or module should be reviewed)
(0124285)
shuehner (administrator)
2020-11-11 18:47

Attached patch is enough to fix the issue as reported affecting unrelated junit tests.
Maybe reviewing the other wrong methods should be split out into separate issue to not delay fixing this first problem.
(0124602)
Mery Anelo (developer)
2020-11-24 23:56

Test plan:

- From the back office
- Run JUnit test org.openbravo.test.createlinesfrom.CreateLinesFromTest
- Check that there is no WARNING for Unbalanced calls to setAdminMode and restorePreviousMode.

- Make use and check the modified methods. Verify that WARNING for Unbalanced calls to setAdminMode and restorePreviousMode is not recorded in the log.
(0124603)
hgbot (developer)
2020-11-24 23:57

Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii/-/merge_requests/6 [^]

- Issue History
Date Modified Username Field Change
2020-11-11 18:02 shuehner New Issue
2020-11-11 18:02 shuehner Assigned To => Jorge Bravo
2020-11-11 18:03 shuehner Note Added: 0124284
2020-11-11 18:27 shuehner Relationship added related to 0045429
2020-11-11 18:47 shuehner File Added: 45428.diff
2020-11-11 18:48 shuehner Note Added: 0124285
2020-11-12 08:17 Jorge Bravo Assigned To Jorge Bravo => Mery Anelo
2020-11-24 23:56 Mery Anelo Note Added: 0124602
2020-11-24 23:57 hgbot Note Added: 0124603
2020-11-25 00:01 Mery Anelo Status new => scheduled


Copyright © 2000 - 2009 MantisBT Group
Powered by Mantis Bugtracker