Perspective - Binding issue on loading

8.1.8

I get error on binding while loading page, it appears when I use an object in expression and try to access a key throw a script. Error appear shortly but it’s agressent.

2021-08-06_10h27_00

image

2021-08-06_10h31_21

It’s hard to tell without seeing all of the pieces, but while a KeyError is definitely encountered when looking for a key “enabled”, it appears to be the “enabled” key of a “myTrigger” object, not the typeAction object you supplied a screenshot for. Could you provide insight into the myTrigger object?

I have 3 types of trigger, myTrigger is the active one and comes from type_action in that case

def transform(self, value, quality, timestamp):
	"""
	Transform the incoming value and return a result.

	Arguments:
		self: A reference to the component this binding is configured on.
		value: The incoming value from the binding or the previous transform.
		quality: The quality code of the incoming value.
		timestamp: The timestamp of the incoming value as a java.util.Date
	"""
	classes="Table/tbl-txt-center-bold Text/txt-lbl-overflow-hidden Colors/borderColor-black Text/txt-desc"
	
	try:
		if not "Alerts" in value["color_name"]:
			if not self.view.params.alert_value_path is None and not self.view.params.alert_value_path=="":
				my_codes = _Functions.getConstDict(self.view.custom.severity_path)
				my_codes = _Functions.reverseDict(my_codes)
				alert_code = my_codes[str(value["alert"])]
			else:
				alert_code = ""
	except:
		return	
#MODE
	if value["type"]=="mode":
		if not value["text_classes"] is None:
			classes += value["text_classes"]
		
		if not alert_code=="" and value["myTrigger"]["active"] and value["alert"] > 0:
			return classes + " Alerts/backgroundColor-" + alert_code + " Objects/toggle-pointer-enabled"
		elif value["myTrigger"]["pending"]:
			return classes + " Colors/backgroundColor-" + value["color_name"] + "Light-" + value["color_name"] + "Dark_blink Colors/color-white Objects/toggle-pointer-enabled"
		elif value["myTrigger"]["active"]:
			return classes + " Colors/backgroundColor-" + value["color_name"] + "Light Colors/color-white Objects/toggle-pointer-enabled" #Colors/backgroundColor-green
		elif value["myTrigger"]["can_request"]:
			return classes + " Colors/backgroundColor-" + value["color_name"] + "Dark Colors/color-white Objects/toggle-pointer-enabled"
		else:
			if not value["has_needs"]:
				return classes + " Colors/backgroundColor-grayLight Colors/color-gray Objects/toggle-pointer-disabled"
		return classes + " Colors/backgroundColor-grayLight Colors/color-gray Objects/toggle-pointer-enabled"
#ACTION
	elif value["type"]=="action":
		if (not value["myTrigger"]["enabled"] or value["myTrigger"]["enabled"] is None) and not value["myTrigger"]["started"] and not value["myTrigger"]["custom_view_exist"]:
			return classes + " Colors/backgroundColor-grayLight Colors/color-gray Objects/toggle-pointer-enabled"#Colors/txt-disabled-color"# Objects/toggle-pointer-disabled"
		
		if not value["text_classes"] is None and not value["text_classes"]=="":
			std_color = value["text_classes"]
		else:
			std_color = "Colors/color-white"
		
		if value["myTrigger"]["custom_view_exist"] and not value["myTrigger"]["can_start"]:
			return classes + " Colors/backgroundColor-grayLight Colors/color-gray Objects/toggle-pointer-enabled"
		elif value["myTrigger"]["risky"] and value["myTrigger"]["enabled"] and not value["myTrigger"]["started"]:
			return classes + " Colors/backgroundColor-amber " + std_color + " Objects/toggle-pointer-enabled"
		elif value["myTrigger"]["started"] and not value["myTrigger"]["ended"]: #value["enabled"] and 
			return classes + " Colors/backgroundColor-" + value["color_name"]  + "-" + value["color_name"] + "Light_blink " + std_color + " Objects/toggle-pointer-disabled"
		elif value["myTrigger"]["enabled"] and value["myTrigger"]["signal"]:
			return classes + " Colors/backgroundColor-" + value["color_name"] + "Light " + std_color + " Objects/toggle-pointer-disabled"
		return std_color + " " + classes + " Colors/backgroundColor-" + value["color_name"] + " Objects/toggle-pointer-enabled"
#TRIGGER
	elif value["type"]=="trigger":
		if not value["text_classes"] is None and not value["text_classes"]=="":
			std_color = value["text_classes"]
		else:
			std_color = "Colors/color-white"
		
		if "Alerts" in value["color_name"]:
			if value["myTrigger"]["enabled"] and not value["myTrigger"]["signal"]:
				return classes + " " + value["color_name"] + " " + " Objects/toggle-pointer-enabled"
			elif value["myTrigger"]["enabled"] and value["myTrigger"]["signal"]:
				return classes + " " + value["color_name"] + "_blink Objects/toggle-pointer-disabled "
			return classes + " " + value["color_name"] + " " + " Objects/toggle-pointer-disabled"
		else:	
			if value["myTrigger"]["enabled"] and not value["myTrigger"]["signal"]:
				return classes + " Colors/backgroundColor-" + value["color_name"] + " " + std_color + " Objects/toggle-pointer-enabled"
			elif value["myTrigger"]["enabled"] and value["myTrigger"]["signal"]:
				return classes + " Colors/backgroundColor-" + value["color_name"] + "-" + value["color_name"] + "Light_blink Objects/toggle-pointer-disabled " + std_color
			return classes + " Colors/backgroundColor-grayLight Colors/color-gray Objects/toggle-pointer-disabled"
	return value["type"]

What you’re encountering is that the binding has not resolved by the time you try to access the enabled key. You could either opt-out of the overlay in the binding dialog, or you could gracefully handle the KeyError within the script you provided:

try:
    ...
    elif value["type"] == "action":
        if (not value["myTrigger"]["enabled"] or ...
except KeyError:
    # do something else here

Why that issue is newer in 8.1.8 ? I nerver encounter that before, and many of our pages has that issue now.