From 19999167b9896bd122060d50489afa9c5085aaec Mon Sep 17 00:00:00 2001 From: arcuri82 Date: Mon, 23 Feb 2026 12:42:57 +0100 Subject: [PATCH] fixed wrong shift of FKs --- .../core/problem/rest/service/RestSecurityBuilder.kt | 2 +- .../core/search/gene/sql/SqlForeignKeyGene.kt | 10 ---------- .../core/search/gene/sql/SqlPrimaryKeyGene.kt | 11 +++++++++++ .../main/kotlin/org/evomaster/core/sql/SqlAction.kt | 3 ++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestSecurityBuilder.kt b/core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestSecurityBuilder.kt index 148a17b65b..802ad31ab4 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestSecurityBuilder.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestSecurityBuilder.kt @@ -403,7 +403,7 @@ class RestSecurityBuilder { // Create a copy of the individual val copy = target.copy() as RestIndividual - val actionCopy = copy.seeMainExecutableActions().last() as RestCallAction + val actionCopy = copy.seeMainExecutableActions().last() val genes = GeneUtils.getAllStringFields(actionCopy.parameters) .filter { it.staticCheckIfImpactPhenotype() } diff --git a/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlForeignKeyGene.kt b/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlForeignKeyGene.kt index e975c880af..571d84c39a 100644 --- a/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlForeignKeyGene.kt +++ b/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlForeignKeyGene.kt @@ -59,16 +59,6 @@ class SqlForeignKeyGene( throw IllegalArgumentException("Invalid delta: $delta") } uniqueId += delta - if(isBound()){ - val ind = getRoot() as EnterpriseIndividual - val action = ind.seeSqlDbActions().find{it.insertionId == uniqueIdOfPrimaryKey} - ?: throw IllegalStateException("FK in $uniqueId is bound to PK $uniqueIdOfPrimaryKey," + - " but there is no action found for it") - if(!action.representExistingData) { - // as the ids of existing data is never modified, we shall not change the links to them - uniqueIdOfPrimaryKey += delta - } - } } diff --git a/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlPrimaryKeyGene.kt b/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlPrimaryKeyGene.kt index 8d77b381ff..17563f0337 100644 --- a/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlPrimaryKeyGene.kt +++ b/core/src/main/kotlin/org/evomaster/core/search/gene/sql/SqlPrimaryKeyGene.kt @@ -1,6 +1,7 @@ package org.evomaster.core.search.gene.sql import org.evomaster.core.output.OutputFormat +import org.evomaster.core.problem.enterprise.EnterpriseIndividual import org.evomaster.core.search.gene.root.CompositeGene import org.evomaster.core.search.gene.Gene import org.evomaster.core.search.impact.impactinfocollection.sql.SqlPrimaryKeyGeneImpact @@ -50,6 +51,16 @@ class SqlPrimaryKeyGene(name: String, if(delta <= 0){ throw IllegalArgumentException("Invalid delta: $delta") } + + //update all FKs pointing to this one + val ind = getRoot() as EnterpriseIndividual + ind.seeSqlDbActions() + .flatMap { it.seeAllGenes() } + .filterIsInstance() + .filter{it.isBound() && it.uniqueIdOfPrimaryKey == uniqueId} + .forEach { it.uniqueIdOfPrimaryKey += delta } + // as the ids of existing data is never modified, we shall not change the links to them + uniqueId += delta } diff --git a/core/src/main/kotlin/org/evomaster/core/sql/SqlAction.kt b/core/src/main/kotlin/org/evomaster/core/sql/SqlAction.kt index 31d1be4bbf..11d2d1c20a 100644 --- a/core/src/main/kotlin/org/evomaster/core/sql/SqlAction.kt +++ b/core/src/main/kotlin/org/evomaster/core/sql/SqlAction.kt @@ -91,7 +91,6 @@ class SqlAction( if(delta <= 0){ throw IllegalArgumentException("Invalid delta: $delta") } - insertionId += delta seeAllGenes().forEach { g -> if(g is SqlPrimaryKeyGene) { @@ -100,6 +99,8 @@ class SqlAction( g.shiftIdBy(delta) } } + + insertionId += delta }