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

exceptionfactory 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 c11dfb408fd NIFI-15776 Set migration-added non-dynamic properties as 
environmental changes in versioned flows (#11086)
c11dfb408fd is described below

commit c11dfb408fd1c6f0b7cdd822be7a71465244dbea
Author: Pierre Villard <[email protected]>
AuthorDate: Wed Apr 1 17:07:17 2026 +0200

    NIFI-15776 Set migration-added non-dynamic properties as environmental 
changes in versioned flows (#11086)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../apache/nifi/util/FlowDifferenceFilters.java    | 52 +++++++++++++-
 .../nifi/util/TestFlowDifferenceFilters.java       | 81 ++++++++++++++++++++++
 2 files changed, 132 insertions(+), 1 deletion(-)

diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/util/FlowDifferenceFilters.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/util/FlowDifferenceFilters.java
index e6f8d97e482..1d952864f5a 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/util/FlowDifferenceFilters.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/util/FlowDifferenceFilters.java
@@ -103,7 +103,8 @@ public class FlowDifferenceFilters {
             || isControllerServiceCreatedForNewProperty(difference, 
evaluatedContext)
             || isPropertyParameterizationRename(difference, evaluatedContext)
             || isPropertyRenameWithMatchingValue(difference, evaluatedContext)
-            || isSelectedRelationshipChangeForNewRelationship(difference, 
flowManager);
+            || isSelectedRelationshipChangeForNewRelationship(difference, 
flowManager)
+            || isPropertyAddedFromMigration(difference, flowManager);
     }
 
     public static boolean isBundleChange(final FlowDifference difference) {
@@ -909,6 +910,55 @@ public class FlowDifferenceFilters {
         return evaluatedContext.propertyRenamesWithMatchingValues().isEmpty() 
? false : 
evaluatedContext.propertyRenamesWithMatchingValues().contains(difference);
     }
 
+    /**
+     * Determines whether a PROPERTY_ADDED difference is an environmental 
change because the added property is a
+     * non-dynamic property defined in the component code. Non-dynamic 
properties are declared through
+     * {@link ConfigurableComponent#getPropertyDescriptors()} and cannot be 
added by users. When a PROPERTY_ADDED
+     * diff exists for such a property, it means the component's code was 
updated (e.g., via NiFi upgrade or bundle
+     * version change) and migration added the property. This is an 
environmental change regardless of whether a
+     * corresponding BUNDLE_CHANGED diff is present, because the VCI baseline 
may already have resolved bundles
+     * (e.g., after {@code discoverCompatibleBundles} during import).
+     *
+     * <p>Only Processors and Controller Services are considered because these 
are the component types that carry
+     * properties within versioned process groups.</p>
+     *
+     * <p>Trade-off: if a user subsequently edits a migration-added property, 
that edit will also be classified as
+     * environmental because the diff relative to the registry is still 
PROPERTY_ADDED (the registry version predates
+     * the migration). This means such edits will not make the flow dirty. 
However, the change remains visible in the
+     * "Show Local Changes" environmental view, and when the user commits for 
any other reason, the full flow
+     * (including the edited property) is saved to the registry.</p>
+     */
+    private static boolean isPropertyAddedFromMigration(final FlowDifference 
difference, final FlowManager flowManager) {
+        if (difference.getDifferenceType() != DifferenceType.PROPERTY_ADDED) {
+            return false;
+        }
+
+        final Optional<String> fieldName = difference.getFieldName();
+        if (fieldName.isEmpty()) {
+            return false;
+        }
+
+        final VersionedComponent componentB = difference.getComponentB();
+        final ComponentNode componentNode;
+        if (componentB instanceof InstantiatedVersionedProcessor) {
+            componentNode = 
flowManager.getProcessorNode(componentB.getInstanceIdentifier());
+        } else if (componentB instanceof 
InstantiatedVersionedControllerService) {
+            componentNode = 
flowManager.getControllerServiceNode(componentB.getInstanceIdentifier());
+        } else {
+            componentNode = null;
+        }
+
+        return isNotDynamicProperty(fieldName.get(), componentNode);
+    }
+
+    private static boolean isNotDynamicProperty(final String propertyName, 
final ComponentNode componentNode) {
+        final ConfigurableComponent component = componentNode == null ? null : 
componentNode.getComponent();
+        final List<PropertyDescriptor> descriptors = component == null ? 
List.of() : component.getPropertyDescriptors();
+        return descriptors.stream()
+                .map(PropertyDescriptor::getName)
+                .anyMatch(propertyName::equals);
+    }
+
     private static Optional<String> getComponentInstanceIdentifier(final 
FlowDifference difference) {
         final Optional<String> identifierB = 
getComponentInstanceIdentifier(difference.getComponentB());
         if (identifierB.isPresent()) {
diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java
index 1269f244a2f..6466a082c72 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java
@@ -659,6 +659,87 @@ public class TestFlowDifferenceFilters {
         assertTrue(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
     }
 
+    @Test
+    public void testPropertyAddedFromMigrationOnProcessor() {
+        final FlowManager flowManager = Mockito.mock(FlowManager.class);
+        final ProcessorNode processorNode = Mockito.mock(ProcessorNode.class);
+        final ConfigurableComponent configurableComponent = 
Mockito.mock(ConfigurableComponent.class);
+
+        final String propertyName = "Table";
+        final String instanceId = "processor-instance";
+
+        
Mockito.when(flowManager.getProcessorNode(instanceId)).thenReturn(processorNode);
+        
Mockito.when(processorNode.getComponent()).thenReturn(configurableComponent);
+        
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(
+                new PropertyDescriptor.Builder().name(propertyName).build(),
+                new PropertyDescriptor.Builder().name("Other 
Property").build()));
+
+        final VersionedProcessor registryProcessor = new VersionedProcessor();
+        final InstantiatedVersionedProcessor localProcessor = new 
InstantiatedVersionedProcessor(instanceId, "group-id");
+        final FlowDifference difference = new StandardFlowDifference(
+                DifferenceType.PROPERTY_ADDED, registryProcessor, 
localProcessor, propertyName, null, "someValue", "Property added");
+
+        assertTrue(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
+    }
+
+    @Test
+    public void testPropertyAddedFromMigrationOnControllerService() {
+        final FlowManager flowManager = Mockito.mock(FlowManager.class);
+        final ControllerServiceNode controllerServiceNode = 
Mockito.mock(ControllerServiceNode.class);
+        final ConfigurableComponent configurableComponent = 
Mockito.mock(ConfigurableComponent.class);
+
+        final String propertyName = "New Service Property";
+        final String instanceId = "service-instance";
+
+        
Mockito.when(flowManager.getControllerServiceNode(instanceId)).thenReturn(controllerServiceNode);
+        
Mockito.when(controllerServiceNode.getComponent()).thenReturn(configurableComponent);
+        
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(
+                new PropertyDescriptor.Builder().name(propertyName).build()));
+
+        final VersionedControllerService registryService = new 
VersionedControllerService();
+        final InstantiatedVersionedControllerService localService = new 
InstantiatedVersionedControllerService(instanceId, "group-id");
+        final FlowDifference difference = new StandardFlowDifference(
+                DifferenceType.PROPERTY_ADDED, registryService, localService, 
propertyName, null, "value", "Property added on service");
+
+        assertTrue(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
+    }
+
+    @Test
+    public void testDynamicPropertyAddedIsNotEnvironmentalChange() {
+        final FlowManager flowManager = Mockito.mock(FlowManager.class);
+        final ProcessorNode processorNode = Mockito.mock(ProcessorNode.class);
+        final ConfigurableComponent configurableComponent = 
Mockito.mock(ConfigurableComponent.class);
+
+        final String instanceId = "processor-instance";
+
+        
Mockito.when(flowManager.getProcessorNode(instanceId)).thenReturn(processorNode);
+        
Mockito.when(processorNode.getComponent()).thenReturn(configurableComponent);
+        
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(
+                new PropertyDescriptor.Builder().name("Static 
Property").build()));
+
+        final VersionedProcessor registryProcessor = new VersionedProcessor();
+        final InstantiatedVersionedProcessor localProcessor = new 
InstantiatedVersionedProcessor(instanceId, "group-id");
+        final FlowDifference difference = new StandardFlowDifference(
+                DifferenceType.PROPERTY_ADDED, registryProcessor, 
localProcessor, "User Dynamic Property", null, "value", "Dynamic property 
added");
+
+        assertFalse(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
+    }
+
+    @Test
+    public void 
testPropertyAddedFromMigrationReturnsFalseWhenProcessorNotFound() {
+        final FlowManager flowManager = Mockito.mock(FlowManager.class);
+
+        final String instanceId = "missing-processor";
+        
Mockito.when(flowManager.getProcessorNode(instanceId)).thenReturn(null);
+
+        final VersionedProcessor registryProcessor = new VersionedProcessor();
+        final InstantiatedVersionedProcessor localProcessor = new 
InstantiatedVersionedProcessor(instanceId, "group-id");
+        final FlowDifference difference = new StandardFlowDifference(
+                DifferenceType.PROPERTY_ADDED, registryProcessor, 
localProcessor, "Table", null, "value", "Property added");
+
+        assertFalse(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
+    }
+
     @DynamicProperty(name = "Dynamic Property", value = "Value", description = 
"Allows dynamic properties")
     private static class DynamicAnnotationProcessor extends AbstractProcessor {
         @Override

Reply via email to