Perspective: Setting property to dictionary in script appends rather than replaces

v8.0.15

Update: I found some strange behaviour in the tagBrowse function I’m using which looks to be the cause… still looking…

I’m not sure if I’m doing something wrong, but these lines are appending the dictionary i’ve created in script onto the end of my properties, instead of replacing the data in the properties… I don’t see an issue when replacing my code with a simple dictionary and setting that to a component property. Look for the “<<<” in the code for specific comments

self.getSibling("ViewCanvas").props.instances = instances
self.view.custom.tags = instances

This is my full code:

def runAction(self, event):
	"""
	This event is fired when the 'action' of the component occurs.

	Arguments:
		self: A reference to the component that is invoking this function.
		event: An empty event object.
	"""
	# builds the instances array for the View Canvas component to display the relevant room devices

	self.getSibling("ViewCanvas").props.instances = {} # <<< I tried adding this into the start to wipe the property first.. no luck
	# get a list of all status tags from the house room devices
	statusTags = tags.browseTags(path='[default]House Room Control', filter={'name':"Status"})
	# read the status tags and produce a list of values indicating off/on status (false/true)
	statusVals = system.tag.readBlocking(statusTags)
	statusVals = [tag.value > 0 for tag in statusVals]
	
	statuses = zip(statusTags, statusVals)
	# get only the on or the off devices, based on dropdown selection
	selectedValue = self.props.value == 'Active'
	# get the path to the UDT Instance by removing the last element (the tag) from the path and filter by selection
	tagPaths = ['/'.join(str(status[0]).split('/')[0:-1]) for status in statuses if status[1] == selectedValue]
	
	instances = []
	prevRoomName = ''
	roomName = ''
	
	for path in tagPaths:
		# get the config of the tag so we can get its UDTType defintion path
		cfg = system.tag.getConfiguration(path)
		UDTInst = cfg[0].get('typeId')
		
		# if its a UDT, then add it to the instances list
		if UDTInst != None:
			# path is in the format: [default]House Room Control/<Room Name>/<Device/Tag Name>
			tagParentPath = '/'.join(str(path).split("/")[0:-1])
			tagName = str(path).split("/")[-1]
			roomName = tagParentPath.split('/')[-1]
			
			# if this is a new room, then add the room name as a subtitle
			if roomName != prevRoomName:
				item = {}
				item['position'] = 'relative'
				item['top'] = '0px'
				item['left'] = '0px'
				item['bottom'] = 'auto'
				item['right'] = 'auto'
				item['zIndex'] = 'auto'
				item['width'] = 'auto'
				item['height'] = 'auto'
				item['viewPath'] = 'Templates/Cards/Subtitle w Icon'
				viewParams = {'title':roomName,'showIcon':0}
				item['viewParams'] = viewParams
				style = {'classes':''}
				item['style'] = style
				
				instances.append(item)
			
			# add the required fields for the instance to a dictionary, then add it into the instances list
			item = {}
			item['position'] = 'relative'
			item['top'] = '0px'
			item['left'] = '0px'
			item['bottom'] = 'auto'
			item['right'] = 'auto'
			item['zIndex'] = 'auto'
			item['width'] = 'auto'
			item['height'] = 'auto'
			item['viewPath'] = 'Templates/Room Devices/' + UDTInst.split('/')[-1]
			viewParams = {'tagParentPath':tagParentPath,'tagName':tagName}
			item['viewParams'] = viewParams
			style = {'classes':''}
			style["borderBottomColor"] = "#ffffff8A"
			style["borderBottomStyle"] = "solid"
			style["borderBottomWidth"] = "0.5px"		
			item['style'] = style
			
			instances.append(item)
			prevRoomName = roomName
	
	# set the view canvas' instances to the new dictionary
	self.getSibling("ViewCanvas").props.instances = instances # <<< This line should replace the View Canvas instances, however it's appending it to the end of the instances data instead??

I found the issue. It was with the tags.browseTags() function I was using (System.tag.browse OR in filter). I was calling the function without setting the 3rd argument to a blank list, which meant that its results were being appended to the last results each time it was called. I don’t really understand why this value would still even exist though across calls??

def browseTags( path='[default]', filter={}, resultaat=[] ):
	# see system.tag.browse() doc
	
	# Call the browse function for folders, do not use the filter
	results = system.tag.browse( path, {} )
#	results = system.tag.browse( path, {'tagType':'Folder'} or {'tagType':'UdtInstance'} ) # does not work
	for result in results.getResults():
		fullPath = str( result['fullPath'] )
		if result['hasChildren'] == True: # recursive call when folder or UdtInstance
			resultaat = browseTags( fullPath, filter, resultaat )
        
	# Call the browse function voor tags, use filter
	results = system.tag.browse( path, filter )
	for result in results.getResults():
		fullPath = str( result['fullPath'] )
		if result['hasChildren'] == False and fullPath.find( '_types_' ) == -1: # if not a tag-type then store
			resultaat.append( fullPath ) 
	
 	return resultaat