Is it possible to pass variable from gateway scope to client scope?

One of the datatypes somewhere in the structure you’re passing into jsonEncode is more than likely not a real dict/list type and jsonEncode barfs on them. There was a recent forum discussion about this failure symptom.

This is a problem with duck-typing languages in general. As I put it to my colleague, something in the structure can walk like a duck and quack like a duck, and has been passing as a duck for a very long time, but when I asked it to lay an egg it fell over and died.

1 Like

Interesting! I’ll see if I have any foxes amongst my ducks and I’ll put a ducksuit on them :slight_smile: I’m betting it could be, as Paul mentioned in that post, maybe a QualifiedValue got in there… Cheers

In my case, it was a bit more hard to spot, as some values that had come through Perspective properties at some point had been turned into PropertyTreeScriptWrapper$ObjectWrapper and PropertyTreeScriptWrapper$ArrayWrapper elements that were very good at imitating dicts and lists until they got into jsonEncode.

It’s got barely minutes of testing on it, but this snippet of code helped me spot my bad elements:

[EDIT: Removed this snippet as I put a more robust one over on this post.]

might have been a boy duck… :innocent:

/me runs away

4 Likes

and there it is…

label 			<type 'unicode'>
displayPath 	<type 'str'>
source 			<type 'com.inductiveautomation.ignition.common.QualifiedPath'>
tagProvider 	<type 'str'>
tagPath 		<type 'str'>
name 			<type 'unicode'>
eventTime 		<type 'java.util.Date'>
state 			<type 'str'>

1 Like

A better/more idiomatic way to do this is to duck-type via hasattr; see the author’s solution in this SO post:

1 Like

This is one of the best threads I have read. Entertaining, light (from one viewpoint), very deep (from another), and full of really good information. Thanks!

Hopefully not wandering too far off topic here, but how does hasattr(xxx, '__getitem__') return false on a PropertyTreeScriptWrapper$ObjectWrapper? It has a keys() method and you can get sub-items using xxx[key]! It’s like a duck missing a foot but still able to swim and walk somehow…

Jython’s a little bit weird.
image