From 5cee129603e423df46169c4da8b0438b8fbe3250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Thu, 13 Oct 2022 16:04:54 +0200 Subject: [PATCH] [core] Check existence of group or list attributes correctly "hasAttribute" was previously never called before attempting to access an attribute. With the addition of internal attributes, we want to check the attribute's/internal attribute's before accessing it to avoid KeyError exceptions. "hasAttribute" (and the newly added "hasInternalAttribute") would not parse the attribute's name before checking for its existence, meaning that errors could be generated for list or group attributes as their checked name could contain other elements (e.g. "featuresFolder[0]" for a ListAttribute named "featuresFolder"). --- meshroom/core/node.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/meshroom/core/node.py b/meshroom/core/node.py index 54158f39bd..9571175794 100644 --- a/meshroom/core/node.py +++ b/meshroom/core/node.py @@ -608,10 +608,18 @@ def getInternalAttributes(self): @Slot(str, result=bool) def hasAttribute(self, name): + # Complex name indicating group or list attribute: parse it and get the + # first output element to check for the attribute's existence + if "[" in name or "." in name: + p = self.attributeRE.findall(name) + return p[0][0] in self._attributes.keys() or p[0][1] in self._attributes.keys() return name in self._attributes.keys() @Slot(str, result=bool) def hasInternalAttribute(self, name): + if "[" in name or "." in name: + p = self.attributeRE.findall(name) + return p[0][0] in self._internalAttributes.keys() or p[0][1] in self._internalAttributes.keys() return name in self._internalAttributes.keys() def _applyExpr(self):