This is an automated email from the ASF dual-hosted git repository.

nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 3dc86fdfd8 Fixed: Remove error after test rollback (OFBIZ-13172)
3dc86fdfd8 is described below

commit 3dc86fdfd8756dc2d5d2c52367ff4309da70d675
Author: Nicolas Malin <[email protected]>
AuthorDate: Tue Nov 12 17:39:19 2024 +0100

    Fixed: Remove error after test rollback (OFBIZ-13172)
    
    When you run entity test with `.gradlew 'ofbiz -t component=entity' after 
the test, entity engine rollback all entity operation. During this process, an 
error appears due to immutable state on GenericValue rollbacked.
    
    To solve it, we'll check first if a gv has been set as immutable. In this 
case we clone it before call the delegator.
---
 .../org/apache/ofbiz/entity/GenericDelegator.java  | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
index 512a3634d6..ea2e46438d 100644
--- 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
+++ 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
@@ -2685,7 +2685,9 @@ public class GenericDelegator implements Delegator {
         if (!this.testMode || this.testRollbackInProgress) {
             throw new IllegalStateException("An attempt was made to store a 
TestOperation during rollback or outside of test mode");
         }
-        this.testOperations.add(testOperation);
+        if (testOperation.getValue().isMutable()) {
+            this.testOperations.add(testOperation);
+        }
     }
 
     /* (non-Javadoc)
@@ -2707,12 +2709,18 @@ public class GenericDelegator implements Delegator {
                 break;
             }
             try {
-                if (testOperation.getOperation().equals(OperationType.INSERT)) 
{
-                    this.removeValue(testOperation.getValue());
-                } else if 
(testOperation.getOperation().equals(OperationType.UPDATE)) {
-                    this.store(testOperation.getValue());
-                } else if 
(testOperation.getOperation().equals(OperationType.DELETE)) {
-                    this.create(testOperation.getValue());
+                GenericValue gv = testOperation.getValue();
+                gv = gv.isMutable()
+                        ? gv
+                        : GenericValue.create(gv);
+                switch (testOperation.getOperation()) {
+                case INSERT -> this.removeValue(gv);
+                case UPDATE -> this.store(gv);
+                case DELETE -> {
+                    if (this.findOne(gv.getEntityName(), 
gv.getPrimaryKey().getAllFields(), false) == null) {
+                        this.create(gv);
+                    }
+                }
                 }
             } catch (GenericEntityException e) {
                 Debug.logWarning(e.toString(), MODULE);

Reply via email to