[core] CompatibilityNode: do not use link expressions as default values for unknown File attributes

When creating a compatibility description for an unknown attribute, do not
consider a link expression as the default value for a File attribute.
This is breaking how the link expression solving system works, as it's resetting
the attribute to its default value after applying the link.
If that expression is kept as the default value, it can be re-evaluated several
times incorrectly.
Added a test case that was failing before that change to illustrate the issue.
This commit is contained in:
Yann Lanthony 2025-02-06 16:46:04 +01:00
parent 4aec741a89
commit 3064cb9b35
2 changed files with 28 additions and 1 deletions

View file

@ -1668,7 +1668,17 @@ class CompatibilityNode(BaseNode):
elif isinstance(value, float): elif isinstance(value, float):
return desc.FloatParam(range=None, **params) return desc.FloatParam(range=None, **params)
elif isinstance(value, str): elif isinstance(value, str):
if isOutput or os.path.isabs(value) or Attribute.isLinkExpression(value): if isOutput or os.path.isabs(value):
return desc.File(**params)
elif Attribute.isLinkExpression(value):
# Do not consider link expression as a valid default desc value.
# When the link expression is applied and transformed to an actual link,
# the systems resets the value using `Attribute.resetToDefaultValue` to indicate
# that this link expression has been handled.
# If the link expression is stored as the default value, it will never be cleared,
# leading to unexpected behavior where the link expression on a CompatibilityNode
# could be evaluated several times and/or incorrectly.
params["value"] = ""
return desc.File(**params) return desc.File(**params)
else: else:
return desc.StringParam(**params) return desc.StringParam(**params)

View file

@ -90,6 +90,23 @@ class TestImportGraphContent:
otherGraph.importGraphContent(graph) otherGraph.importGraphContent(graph)
otherGraph.importGraphContent(graph) otherGraph.importGraphContent(graph)
def test_edgeRemappingOnImportingGraphWithUnkownNodeTypesSeveralTimes(self):
graph = Graph("")
with registeredNodeTypes([SimpleNode]):
nodeA_1 = graph.addNewNode(SimpleNode.__name__)
nodeA_2 = graph.addNewNode(SimpleNode.__name__)
graph.addEdge(nodeA_1.output, nodeA_2.input)
otherGraph = Graph("")
otherGraph.importGraphContent(graph)
otherGraph.importGraphContent(graph)
assert len(otherGraph.nodes) == 4
assert len(otherGraph.compatibilityNodes) == 4
assert len(otherGraph.edges) == 2
def test_importGraphWithUnknownNodeTypesCreatesCompatibilityNodes(self): def test_importGraphWithUnknownNodeTypesCreatesCompatibilityNodes(self):
graph = Graph("") graph = Graph("")