[core] Graph: improve uid conflicts check on deserialization

Only perform uid check when we have both a serialized and a computed
UID.
If the node has not been serialized with a UID, it means that it does not
expect to match a specific value on deserialization.
This commit is contained in:
Yann Lanthony 2025-02-06 16:46:04 +01:00
parent 6b75dcb356
commit f8f03b0bd5

View file

@ -346,7 +346,7 @@ class Graph(BaseObject):
nodeVersions = self.header.get(GraphIO.Keys.NodesVersions, {})
return nodeVersions.get(nodeType, default)
def _evaluateUidConflicts(self, data):
def _evaluateUidConflicts(self, graphContent: dict):
"""
Compare the UIDs of all the nodes in the graph with the UID that is expected in the graph file. If there
are mismatches, the nodes with the unexpected UID are replaced with "UidConflict" compatibility nodes.
@ -357,17 +357,17 @@ class Graph(BaseObject):
Args:
data (dict): the dictionary containing all the nodes to import and their data
"""
for nodeName, nodeData in sorted(data.items(), key=lambda x: self.getNodeIndexFromName(x[0])):
for nodeName, nodeData in sorted(graphContent.items(), key=lambda x: self.getNodeIndexFromName(x[0])):
node = self.node(nodeName)
savedUid = nodeData.get("uid", None)
graphUid = node._uid # Node's UID from the graph itself
serializedUid = nodeData.get("uid", None)
computedUid = node._uid # Node's UID from the graph itself
if savedUid != graphUid and graphUid is not None:
if serializedUid and computedUid and serializedUid != computedUid:
# Different UIDs, remove the existing node from the graph and replace it with a CompatibilityNode
logging.debug("UID conflict detected for {}".format(nodeName))
self.removeNode(nodeName)
n = nodeFactory(nodeData, nodeName, expectedUid=graphUid)
n = nodeFactory(nodeData, nodeName, expectedUid=computedUid)
self._addNode(n, nodeName)
else:
# f connecting nodes have UID conflicts and are removed/re-added to the graph, some edges may be lost: