You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by kd...@apache.org on 2026/03/26 04:14:48 UTC

(nifi) branch main updated: NIFI-15748 Skip inherited parameters when validating asset references (#11042)

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

kdoran pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 937601ffa8f NIFI-15748 Skip inherited parameters when validating asset references (#11042)
937601ffa8f is described below

commit 937601ffa8fd5c6149b5342eb4f99fc5cf5cf916
Author: Bryan Bende <bb...@apache.org>
AuthorDate: Thu Mar 26 00:14:42 2026 -0400

    NIFI-15748 Skip inherited parameters when validating asset references (#11042)
---
 .../apache/nifi/web/api/dto/AssetReferenceDTO.java |  5 ++
 .../nifi/web/api/ParameterContextResource.java     |  4 ++
 .../system/parameters/ParameterContextIT.java      | 53 ++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AssetReferenceDTO.java b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AssetReferenceDTO.java
index 8db542277c9..dae300e9951 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AssetReferenceDTO.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/AssetReferenceDTO.java
@@ -74,4 +74,9 @@ public class AssetReferenceDTO {
     public int hashCode() {
         return Objects.hashCode(id);
     }
+
+    @Override
+    public String toString() {
+        return "AssetReferenceDTO[id=%s, name=%s]".formatted(id, name);
+    }
 }
diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
index f8d7b3f2906..640bcf9defe 100644
--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
+++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ParameterContextResource.java
@@ -800,6 +800,10 @@ public class ParameterContextResource extends AbstractParameterResource {
     private void validateAssetReferences(final ParameterContextDTO parameterContextDto) {
         if (parameterContextDto.getParameters() != null) {
             for (final ParameterEntity entity : parameterContextDto.getParameters()) {
+                if (Boolean.TRUE.equals(entity.getParameter().getInherited())) {
+                    continue;
+                }
+
                 final List<AssetReferenceDTO> referencedAssets = entity.getParameter().getReferencedAssets();
                 if (referencedAssets == null) {
                     continue;
diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/parameters/ParameterContextIT.java b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/parameters/ParameterContextIT.java
index 6e2658fb539..40a609bd79b 100644
--- a/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/parameters/ParameterContextIT.java
+++ b/nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/parameters/ParameterContextIT.java
@@ -1056,6 +1056,59 @@ public class ParameterContextIT extends NiFiSystemIT {
         waitForStoppedProcessor(ingest.getId());
     }
 
+    @Test
+    public void testRemoveInheritedContextWithAssetReference() throws NiFiClientException, IOException, InterruptedException {
+        // Create two child parameter contexts
+        final ParameterContextEntity childContext1 = getClientUtil().createParameterContext("childContext1", Map.of("fileToIngest", ""));
+        final ParameterContextEntity childContext2 = getClientUtil().createParameterContext("childContext2", Map.of("otherParam", "otherValue"));
+
+        // Create an asset in child context 1 and update its parameter to reference the asset
+        final File assetFile = new File("src/test/resources/sample-assets/helloworld.txt");
+        final AssetEntity asset = createAsset(childContext1.getId(), assetFile);
+
+        final ParameterContextUpdateRequestEntity referenceAssetUpdateRequest = getClientUtil().updateParameterAssetReferences(
+                childContext1, Map.of("fileToIngest", List.of(asset.getAsset().getId())));
+        getClientUtil().waitForParameterContextRequestToComplete(childContext1.getId(), referenceAssetUpdateRequest.getRequest().getRequestId());
+
+        // Create a parent context that inherits both child contexts
+        final ParameterContextEntity parentContext = getClientUtil().createParameterContext("parentContext",
+                Collections.emptyMap(), List.of(childContext1.getId(), childContext2.getId()), null);
+
+        // Fetch the parent with inherited parameters included, simulating what the UI does when
+        // loading the parameter context for editing. The response includes inherited parameters
+        // (with inherited=true and referencedAssets populated) from both child contexts.
+        final ParameterContextEntity fetchedParent = getNifiClient().getParamContextClient().getParamContext(parentContext.getId(), true);
+
+        // Verify the fetched parent includes the inherited parameter that references the asset
+        final Set<ParameterEntity> fetchedParams = fetchedParent.getComponent().getParameters();
+        final ParameterEntity inheritedAssetParam = fetchedParams.stream()
+                .filter(p -> "fileToIngest".equals(p.getParameter().getName()))
+                .findFirst()
+                .orElse(null);
+        assertNotNull(inheritedAssetParam);
+        assertTrue(inheritedAssetParam.getParameter().getInherited());
+        assertNotNull(inheritedAssetParam.getParameter().getReferencedAssets());
+        assertFalse(inheritedAssetParam.getParameter().getReferencedAssets().isEmpty());
+
+        // Modify only the inherited contexts list to remove childContext1, keeping all the
+        // parameters from the fetched response intact. This reproduces what the UI sends when
+        // a user removes an inherited context: the full parameter list (including inherited
+        // parameters with asset references from the now-removed context) is still present.
+        fetchedParent.getComponent().setInheritedParameterContexts(
+                fetchedParent.getComponent().getInheritedParameterContexts().stream()
+                        .filter(ref -> ref.getId().equals(childContext2.getId()))
+                        .collect(Collectors.toList()));
+
+        final ParameterContextUpdateRequestEntity removeInheritanceRequest =
+                getNifiClient().getParamContextClient().updateParamContext(fetchedParent);
+        getClientUtil().waitForParameterContextRequestToComplete(parentContext.getId(), removeInheritanceRequest.getRequest().getRequestId());
+
+        // Verify only childContext2 remains as inherited
+        final ParameterContextEntity updatedParent = getNifiClient().getParamContextClient().getParamContext(parentContext.getId(), false);
+        assertEquals(1, updatedParent.getComponent().getInheritedParameterContexts().size());
+        assertEquals(childContext2.getId(), updatedParent.getComponent().getInheritedParameterContexts().get(0).getId());
+    }
+
     @Test
     public void testAssetReferenceAfterRestart() throws NiFiClientException, IOException, InterruptedException {
         // Create Parameter Context