Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0035653Openbravo ERPY. DBSourceManagerpublic2017-03-30 14:022017-09-26 15:25
eduardo_Argal 
alostale 
highmajorsometimes
closedfixed 
5
 
 
AugustoMauch
Core
No
0035653: update.database can fail updating src tables with a check constraint where more than one column participates
Having DB check constraint for a datasource table that is computed based on more than one column, update.database can fail when adding changes to that table.

This can occur if for a record more than one column participating in that contraint gets modified and even the whole changes fulfills the constraint, individual ones don't.

In the case described in steps to reproduce section, checking executed DB statements we can see:

UPDATE OBCQL_QUERY_COLUMN SET UPDATED = $1, UPDATEDBY = $2, HAS_LINK = $3 WHERE OBCQL_QUERY_COLUMN_ID 
= $4
parameters: $1 = '2017-09-12 12:38:30.269373', $2 = '0', $3 = 'Y', $4 = '28F920CD36E14AFBB2025802363E8B02'


UPDATE OBCQL_QUERY_COLUMN SET UPDATED = $1, UPDATEDBY = $2, AD_TAB_ID = $3 WHERE OBCQL_QUERY_COLUMN_ID 
= $4
parameters: $1 = '2017-09-12 12:38:30.280567', $2 = '0', $3 = '186', $4 = '28F920CD36E14AFBB2025802363E8B02'


UPDATE OBCQL_QUERY_COLUMN SET UPDATED = $1, UPDATEDBY = $2, CAN_BE_FILTERED = $3 WHERE OBCQL_QUERY_COLUMN_ID 
= $4
parameters: $1 = '2017-09-12 12:38:30.291775', $2 = '0', $3 = 'Y', $4 = '28F920CD36E14AFBB2025802363E8B02'



Note that changes in individual columns are applied independently, so it's possible to leave row in a temporary inconsistent state.
1. In a clean pi apply attached reproduce-issue-35653.diff patch
2. execute ant update.database
  -> ERROR:
     ...
     [java] 27738 INFO - Updating Application Dictionary data...
     [java] org.postgresql.util.PSQLException: ERROR: new row for relation "obcql_query_column" violates check constraint "obcql_column_whereclause_chk"
     [java] Detail: Failing row contains (28F920CD36E14AFBB2025802363E8B02, 0, 0, Y, 2015-08-03 12:05:45.870978, 0, 2017-09-12 12:50:33.690805, 0, CFDF8EE593F04CFE9709F5AD19A3A573, qty, Qty, null, 10, null, 20, 29, null, W, Y, 186, Y, null, null).
All changes affecting a single row should be applied at once. This would:

1. Solve described issue where database cannot be updated because the record is tried to be set to a temporary incorrect state.
2. Improve performance for some updates by reducing the number of statements required to update.
No tags attached.
related to defect 0036937 closed alostale update.database source data queries current time to DB for each change 
related to defect 0036938 closed alostale dbsm test: src changes not applied 
causes defect 0036984 closed alostale Upgrading from 2.50 to pi some unique constraints are violated 
log WidgetCompilationError.log (18,455) 2017-03-30 14:02
https://issues.openbravo.com/file_download.php?file_id=10623&type=bug
diff reproduce-issue-35653.diff (1,277) 2017-09-12 12:43
https://issues.openbravo.com/file_download.php?file_id=11056&type=bug
Issue History
2017-03-30 14:02eduardo_ArgalNew Issue
2017-03-30 14:02eduardo_ArgalAssigned To => platform
2017-03-30 14:02eduardo_ArgalFile Added: WidgetCompilationError.log
2017-03-30 14:02eduardo_ArgalModules => Core
2017-03-30 14:02eduardo_ArgalTriggers an Emergency Pack => No
2017-03-30 14:06shuehnerIssue Monitored: shuehner
2017-03-30 14:15eduardo_ArgalNote Added: 0095711
2017-04-07 09:02alostaleNote Added: 0095887
2017-04-07 09:02alostaleAssigned Toplatform => eduardo_Argal
2017-04-07 09:02alostaleStatusnew => feedback
2017-06-06 16:01eduardo_ArgalNote Added: 0097169
2017-09-01 13:02ngarciaIssue Monitored: ngarcia
2017-09-04 11:29nitasujenaResolution time => 1506290400
2017-09-04 11:29nitasujenaStatusfeedback => new
2017-09-12 10:19eduardo_ArgalAssigned Toeduardo_Argal => alostale
2017-09-12 12:43alostaleFile Added: reproduce-issue-35653.diff
2017-09-12 12:55alostaleAssigned Toalostale => platform
2017-09-12 12:55alostaleCategory00. Application dictionary => Y. DBSourceManager
2017-09-12 12:55alostaleSummaryCompilation failing after updating a widgets module version => update.database can fail updating src tables with a check constraint where more than one column participates
2017-09-12 12:55alostaleDescription Updatedbug_revision_view_page.php?rev_id=15875#r15875
2017-09-12 12:55alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=15877#r15877
2017-09-12 12:55alostaleProposed Solution updated
2017-09-13 09:51alostaleStatusnew => scheduled
2017-09-13 09:51alostaleAssigned Toplatform => alostale
2017-09-25 10:55alostaleRelationship addedrelated to 0036937
2017-09-25 11:16alostaleRelationship addedrelated to 0036938
2017-09-25 11:23hgbotCheckin
2017-09-25 11:23hgbotNote Added: 0099526
2017-09-25 11:23hgbotCheckin
2017-09-25 11:23hgbotNote Added: 0099528
2017-09-25 11:23hgbotStatusscheduled => resolved
2017-09-25 11:23hgbotResolutionopen => fixed
2017-09-25 11:23hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/5778a1eb46718a99ff7479e483a108f24a529198 [^]
2017-09-25 11:23hgbotCheckin
2017-09-25 11:23hgbotNote Added: 0099529
2017-09-25 11:23hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/devel/pi/rev/5778a1eb46718a99ff7479e483a108f24a529198 [^] => http://code.openbravo.com/erp/devel/dbsm-main/rev/d0d4150b7e96d10312b126671ea0f7e693c61e1b [^]
2017-09-25 12:22alostaleReview Assigned To => AugustoMauch
2017-09-25 15:58AugustoMauchNote Added: 0099563
2017-09-25 15:58AugustoMauchStatusresolved => closed
2017-09-26 15:25hudsonbotCheckin
2017-09-26 15:25hudsonbotNote Added: 0099589
2017-10-02 13:52inigosanchezRelationship addedcauses 0036984

Notes
(0095711)
eduardo_Argal   
2017-03-30 14:15   
You can use:
https://bitbucket.org/gpscode/but_com.openbravo.retail.reports-customwidgets [^]

Install in rev 1 or 2 (depending on date format)
update to rev 3
(0095887)
alostale   
2017-04-07 09:02   
I don't have access to that repo. Can you provide access to it or attach a simplified version with the failing code?
(0097169)
eduardo_Argal   
2017-06-06 16:01   
Access has been granted. You should be able to access now. Sorry for the inconvenience
(0099526)
hgbot   
2017-09-25 11:23   
Repository: erp/devel/dbsm-main
Changeset: ee395fa9372021a33722a4808c9945e108f818e0
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Mon Sep 25 10:46:14 2017 +0200
URL: http://code.openbravo.com/erp/devel/dbsm-main/rev/ee395fa9372021a33722a4808c9945e108f818e0 [^]

related to bug 35653: update.database can fail in src tables with checks

  Added test case that covers current failing scenario: a src table with a check
  contraint including 2 columns and src updates affecting those 2 columns.

  Current implementation fails in this case because each column is tried to be
  updated individually which leads to an invalid state for the check.

---
M src-test/src/org/openbravo/dbsm/test/DBSMTestSuite.java
A src-test/data/datachanges/v1/TEST.xml
A src-test/data/datachanges/v2/TEST.xml
A src-test/model/constraints/TWO_COLS_CHECK.xml
A src-test/src/org/openbravo/dbsm/test/sourcedata/SourceDataSuite.java
A src-test/src/org/openbravo/dbsm/test/sourcedata/SourcedataUpdates.java
---
(0099528)
hgbot   
2017-09-25 11:23   
Repository: erp/devel/pi
Changeset: 5778a1eb46718a99ff7479e483a108f24a529198
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Mon Sep 25 11:04:14 2017 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/5778a1eb46718a99ff7479e483a108f24a529198 [^]

fixed bug 36937, fixed bug 35653: dbsm fixing those 2 issues

---
M src-db/database/lib/dbsourcemanager.jar
---
(0099529)
hgbot   
2017-09-25 11:23   
Repository: erp/devel/dbsm-main
Changeset: d0d4150b7e96d10312b126671ea0f7e693c61e1b
Author: Asier Lostalé <asier.lostale <at> openbravo.com>
Date: Mon Sep 25 10:48:54 2017 +0200
URL: http://code.openbravo.com/erp/devel/dbsm-main/rev/d0d4150b7e96d10312b126671ea0f7e693c61e1b [^]

fixed bug 35653: update.database can fail in src tables with check contraints

  When updating database with changes in src tables that have check contraints,
  process could fail if those contraints included more than one column of that
  table.

  The problem was caused because changes in each column for the same row were
  applied as individual SQL statements. This caused to be possible to reach an
  inconsistent state.

  Now all data changes for a single row are applied altogether.

---
M src/org/apache/ddlutils/platform/PlatformImplBase.java
---
(0099563)
AugustoMauch   
2017-09-25 15:58   
Code reviewed and verified
(0099589)
hudsonbot   
2017-09-26 15:25   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/8fa643b4437e [^]
Maturity status: Test