Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

Proposed changes

When importing nodes from NodeSet2.xml using UANodeSet.Import(), parent-child relationships were not established. This caused GetChildren() to return empty and prevented proper hierarchy navigation.

Root cause: The import process stored ParentNodeId in the Handle property but never established the bidirectional parent-child relationship in memory.

Solution: Added post-processing step that:

  • Reads ParentNodeId from Handle property on imported nodes
  • Sets Parent property on child nodes
  • Adds children to parent's internal collection via AddChild()
  • Feature is opt-in via linkParentChild parameter (defaults to false for backward compatibility)

Example usage:

var nodeSet = UANodeSet.Read(stream);
var nodes = new NodeStateCollection();

// Enable parent-child linking (new opt-in feature)
nodeSet.Import(context, nodes, linkParentChild: true);

// GetChildren() now works correctly
var parentNode = nodes.First(n => n.BrowseName.Name == "ParentObject");
var children = new List<BaseInstanceState>();
parentNode.GetChildren(context, children);  // Returns child nodes

// Default behavior (backward compatible)
nodeSet.Import(context, nodes);  // No parent-child links established

Changes:

  • UANodeSetHelpers.cs: Added LinkParentChildRelationships() method, integrated into Import() with optional linkParentChild parameter (defaults to false)
  • UANodeSetHelpersTests.cs: Added ParentChildReferencesTest() verifying hierarchy navigation when enabled, and ParentChildReferencesDefaultBehaviorTest() verifying backward compatibility

Related Issues

  • Addresses issue where GetChildren() returns empty after importing nodes from NodeSet2.xml files

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

The feature is opt-in to maintain backward compatibility. Default behavior is unchanged - parent-child relationships are NOT established unless explicitly requested via the linkParentChild parameter. This ensures existing code continues to work without modifications. All 7 UANodeSetHelpersTests pass, including new tests verifying both the feature functionality and backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>Missing parent-child references when importing nodes</issue_title>
<issue_description>### Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

When importing nodes from a NodeSet2.xml nodeset and adding those nodes to the server using AddPredefinedNode(SystemContext, node) in the custom nodemanager, the parent-child references are missing. As a result methods such as node.GetChildren() are not working.

Right now I can use a workaround with currentNode?.GetReferences(nodeManager?.SystemContext, references) and filter for the expected children manually.

Expected Behavior

The parent-child references should be present when importing nodesets and adding predefined nodes.

Steps To Reproduce

No response

Environment

- OS: Windows 10, Windows 11
- Environment: Visual Studio Code 1.99.3
- Runtime: NET9.0
- Nuget Version: 1.5.375.457
- Component:
- Server: -
- Client: -

Anything else?

I use the CustomNodeManager2 class with:


nodeSet.Import(SystemContext, predefinedNodes);

foreach (var node in predefinedNodes)
  {
      AddPredefinedNode(SystemContext, node);
  }
AddReverseReferences(externalReferences);

Is this behavior expected?</issue_description>

Comments on the Issue (you are @copilot in this section)

@salihgoncu Hello, Are the parent-child relationships defined properly in the nodeset2.xml file? Could you provide us a sample xml that shows the behavior in question?

Best Regards,
Salih</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

- Added LinkParentChildRelationships method to establish parent-child links after import
- Sets Parent property and adds child to parent's children collection
- Added test to verify parent-child references work correctly after import
- All existing tests continue to pass

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing parent-child references when importing nodes Fix missing parent-child references when importing NodeSet2.xml Dec 8, 2025
Copilot AI requested a review from romanett December 8, 2025 22:44
- Added linkParentChild parameter to Import method (defaults to false)
- Maintains backward compatibility by not establishing parent-child relationships by default
- Added test to verify backward compatibility (default behavior)
- Updated ParentChildReferencesTest to explicitly enable the feature
- All 7 tests pass

Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
Copilot AI changed the title Fix missing parent-child references when importing NodeSet2.xml Add optional parent-child linking when importing NodeSet2.xml Dec 9, 2025
Copilot AI requested a review from marcschier December 9, 2025 07:54
@marcschier marcschier marked this pull request as ready for review December 9, 2025 07:54
@marcschier marcschier merged commit ae03267 into master Dec 9, 2025
216 of 240 checks passed
@romanett romanett deleted the copilot/fix-parent-child-references-import branch December 9, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing parent-child references when importing nodes

4 participants