From 3689c12e9c4c91f5abe86fe5830c68783323e4b1 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 3ff0c6ca..80842e08 100644 --- a/meshroom/core/node.py +++ b/meshroom/core/node.py @@ -611,10 +611,18 @@ class BaseNode(BaseObject): @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):