Script works in designer, not in browser

Hello folks.

I come to you because I’m utterly confused as to what’s wrong with what I’m trying to do.

Here’s the full situation (in case the issue comes from something else than the script):
I have a main view, with a value change script on its parameter. This script sends a message to broadcast the parameter’s new value:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	zone_num = currentValue.value
	system.perspective.sendMessage(
		messageType="page_changed",
		payload={'page': "zone", 'zone_num': zone_num}
	)

The point is to pass this parameter to docks. Which, I believe, is working fine.
One of these docks has this message handler:

def onMessageReceived(self, payload):
	if payload.get('page') in ["zone", ...]: # there are actual values here, not '...'
		self.view.custom.zone_num = payload.get('zone_num')

I display zone_num on the dock, it works, no problem here (again, I believe).

Now, on the dock’s view, I have another custom property, bound 3 properties including zone_num (the others 2 are not supposed to change much), and with this script transform:

def transform(self, value, quality, timestamp):
	try:
		ncu_name = next(z.ncu.name for z in value.devices if z.zone_num == value.zone)
	except StopIteration as e:
		return "ncu not found for zone {}".format(value.zone)
	return {
		'name': ncu_name,
		'alarms': value.alarms.get(ncu_name, 0)
	}

This works fine in the designer:
image image image

All of those are what I’d expect.

Now, when I try this in the browser… The first load shows the good results, I’m guessing because it just shows the defaults.
But if I try to navigate to another zone page, either by changing the url manually or clicking links, it just doesn’t work, and trying to display the object with a label just shows “ncu not found for zone x”.
Another label displays zone_num and it is correct.
I also tried displaying the other 2 properties, alarms and devices, or at least their length, and they also seem correct.

I turned this around in any way I could think of, but I can’t figure it out. I’m completely clueless and have no idea what to even try anymore…
I’ll take any help you wonderful people can provide !

edit: Wait I might be a moron and just forgot that zone_num, when coming from an url parameter, is a string.
I guess I had to type all of this to think about that, huh.

edit 2: Yep, mystery solved. Move along, nothing to see here.

edit 3: I miss type hints.

5 Likes

Rubber duck debugging does it again!

3 Likes

I scratched my head for a few hours on this one. I’m glad you guys are enjoying my idiocy.

1 Like

I got a few posts in my history that follow the same story you did where I figured out my own (in retrospect) obvious mistake. I’m not enjoying your idiocy, it just makes me feel more comfortable with my own :slight_smile: