[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").
This commit is contained in:
Candice Bentéjac 2022-10-13 16:04:54 +02:00
parent 1015ea448a
commit 3689c12e9c

View file

@ -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):