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

pvillard31 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 f62ad76d750 NIFI-15863 - User edits to newly-introduced component 
properties silently classified as environmental changes (#11166)
f62ad76d750 is described below

commit f62ad76d750e979f669355a6b41e82b80e6d3c83
Author: Pierre Villard <[email protected]>
AuthorDate: Tue Apr 21 17:12:07 2026 +0200

    NIFI-15863 - User edits to newly-introduced component properties silently 
classified as environmental changes (#11166)
---
 .../apache/nifi/util/FlowDifferenceFilters.java    | 44 ++++++++----
 .../nifi/util/TestFlowDifferenceFilters.java       | 80 ++++++++++++++++++++--
 2 files changed, 104 insertions(+), 20 deletions(-)

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 dfbc678fa7f..14f5898fe60 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
@@ -943,26 +943,31 @@ public class FlowDifferenceFilters {
 
     /**
      * Determines whether a PROPERTY_ADDED difference is an environmental 
change because the added property is a
-     * non-dynamic property defined in the component code that did not exist 
in the versioned snapshot. 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 and the 
snapshot did not already define it, 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).
+     * non-dynamic property defined in the component code that did not exist 
in the versioned snapshot and whose
+     * current value still matches the descriptor's default. 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 and the snapshot did not already define it, 
it means the component's code was updated
+     * (e.g., via NiFi upgrade or bundle version change) and migration or 
default-value application introduced 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>If the snapshot (component A) already contains a property descriptor 
for the property in question, the
      * property was part of the component definition when the flow was 
committed and the user has intentionally set
      * a value. In that case, this method returns {@code false} so the change 
is treated as a local modification.</p>
      *
+     * <p>If the added value differs from the descriptor's default, the change 
is treated as a user modification and
+     * this method returns {@code false}. This ensures that user edits to 
migration-introduced properties are surfaced
+     * as local changes rather than being silently absorbed into the 
environmental view.</p>
+     *
      * <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>
+     * <p>Trade-off: if a component's {@code migrateProperties} implementation 
sets a newly-introduced static property
+     * to a value that differs from the descriptor's default, that change will 
now be classified as a local
+     * modification rather than environmental. The affected user can 
re-baseline by committing the flow once after the
+     * NAR upgrade. This is preferable to the previous behavior, which 
silently swallowed user edits to
+     * migration-added properties.</p>
      */
     private static boolean isPropertyAddedFromMigration(final FlowDifference 
difference, final FlowManager flowManager) {
         if (difference.getDifferenceType() != DifferenceType.PROPERTY_ADDED) {
@@ -992,15 +997,24 @@ public class FlowDifferenceFilters {
             componentNode = null;
         }
 
-        return isNotDynamicProperty(fieldName.get(), componentNode);
+        if (isDynamicProperty(fieldName.get(), componentNode)) {
+            return false;
+        }
+
+        final PropertyDescriptor descriptor = componentNode == null ? null : 
componentNode.getPropertyDescriptor(fieldName.get());
+        if (descriptor == null) {
+            return true;
+        }
+
+        return Objects.equals(difference.getValueB(), 
descriptor.getDefaultValue());
     }
 
-    private static boolean isNotDynamicProperty(final String propertyName, 
final ComponentNode componentNode) {
+    private static boolean isDynamicProperty(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);
+                .noneMatch(propertyName::equals);
     }
 
     private static Optional<String> getComponentInstanceIdentifier(final 
FlowDifference difference) {
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 57bb547fc05..6c891d35ce2 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
@@ -667,17 +667,24 @@ public class TestFlowDifferenceFilters {
 
         final String propertyName = "Table";
         final String instanceId = "processor-instance";
+        final String defaultValue = "defaultTable";
+
+        final PropertyDescriptor descriptor = new PropertyDescriptor.Builder()
+                .name(propertyName)
+                .defaultValue(defaultValue)
+                .build();
 
         
Mockito.when(flowManager.getProcessorNode(instanceId)).thenReturn(processorNode);
         
Mockito.when(processorNode.getComponent()).thenReturn(configurableComponent);
+        
Mockito.when(processorNode.getPropertyDescriptor(propertyName)).thenReturn(descriptor);
         
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(
-                new PropertyDescriptor.Builder().name(propertyName).build(),
+                descriptor,
                 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");
+                DifferenceType.PROPERTY_ADDED, registryProcessor, 
localProcessor, propertyName, null, defaultValue, "Property added");
 
         assertTrue(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
     }
@@ -690,16 +697,22 @@ public class TestFlowDifferenceFilters {
 
         final String propertyName = "New Service Property";
         final String instanceId = "service-instance";
+        final String defaultValue = "defaultServiceValue";
+
+        final PropertyDescriptor descriptor = new PropertyDescriptor.Builder()
+                .name(propertyName)
+                .defaultValue(defaultValue)
+                .build();
 
         
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()));
+        
Mockito.when(controllerServiceNode.getPropertyDescriptor(propertyName)).thenReturn(descriptor);
+        
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(descriptor));
 
         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");
+                DifferenceType.PROPERTY_ADDED, registryService, localService, 
propertyName, null, defaultValue, "Property added on service");
 
         assertTrue(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
     }
@@ -796,6 +809,63 @@ public class TestFlowDifferenceFilters {
         assertFalse(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
     }
 
+    @Test
+    public void testUserEditOfMigrationAddedPropertyIsNotEnvironmentalChange() 
{
+        final FlowManager flowManager = Mockito.mock(FlowManager.class);
+        final ProcessorNode processorNode = Mockito.mock(ProcessorNode.class);
+        final ConfigurableComponent configurableComponent = 
Mockito.mock(ConfigurableComponent.class);
+
+        final String propertyName = "Record Structure";
+        final String instanceId = "processor-instance";
+        final String defaultValue = "first-option";
+        final String userValue = "second-option";
+
+        final PropertyDescriptor descriptor = new PropertyDescriptor.Builder()
+                .name(propertyName)
+                .defaultValue(defaultValue)
+                .build();
+
+        
Mockito.when(flowManager.getProcessorNode(instanceId)).thenReturn(processorNode);
+        
Mockito.when(processorNode.getComponent()).thenReturn(configurableComponent);
+        
Mockito.when(processorNode.getPropertyDescriptor(propertyName)).thenReturn(descriptor);
+        
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(descriptor));
+
+        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, userValue, "User edited migration-added 
property");
+
+        assertFalse(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
+    }
+
+    @Test
+    public void 
testMigrationAddedPropertyWithNonNullDefaultMatchingLocalValueIsEnvironmentalChange()
 {
+        final FlowManager flowManager = Mockito.mock(FlowManager.class);
+        final ProcessorNode processorNode = Mockito.mock(ProcessorNode.class);
+        final ConfigurableComponent configurableComponent = 
Mockito.mock(ConfigurableComponent.class);
+
+        final String propertyName = "Record Type";
+        final String instanceId = "processor-instance";
+        final String defaultValue = "default-option";
+
+        final PropertyDescriptor descriptor = new PropertyDescriptor.Builder()
+                .name(propertyName)
+                .defaultValue(defaultValue)
+                .build();
+
+        
Mockito.when(flowManager.getProcessorNode(instanceId)).thenReturn(processorNode);
+        
Mockito.when(processorNode.getComponent()).thenReturn(configurableComponent);
+        
Mockito.when(processorNode.getPropertyDescriptor(propertyName)).thenReturn(descriptor);
+        
Mockito.when(configurableComponent.getPropertyDescriptors()).thenReturn(List.of(descriptor));
+
+        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, defaultValue, "Property added by migration 
with default value");
+
+        assertTrue(FlowDifferenceFilters.isEnvironmentalChange(difference, 
null, flowManager));
+    }
+
     @Test
     public void testIsComponentUpdateRequiredForPositionChange() {
         final FlowManager flowManager = Mockito.mock(FlowManager.class);

Reply via email to