'com.inductiveautomation.perspective.gateway.script' object has no attribute 'active_call'

Hi, I have a valueChanged script on a timer that uses an array custom value that keeps getting the below error. Below is also my script and the custom values it uses, active_call is dynamic and can have more instances.

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
  File "<function:valueChanged>", line 3, in valueChanged
AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'active_calls'

	at org.python.core.Py.AttributeError(Py.java:178)
	at org.python.core.PyObject.noAttributeError(PyObject.java:965)
	at org.python.core.PyObject.__getattr__(PyObject.java:959)
	at org.python.pycode._pyx59055.valueChanged$1(<function:valueChanged>:22)
	at org.python.pycode._pyx59055.call_function(<function:valueChanged>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
	at org.python.core.PyFunction.function___call__(PyFunction.java:474)
	at org.python.core.PyFunction.__call__(PyFunction.java:469)
	at org.python.core.PyFunction.__call__(PyFunction.java:464)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:846)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:828)
	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:832)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1009)
	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:897)
	at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:147)
	at com.inductiveautomation.perspective.gateway.model.PropertyChangeScript.access$001(PropertyChangeScript.java:30)
	at com.inductiveautomation.perspective.gateway.model.PropertyChangeScript$ScriptSequencer.run(PropertyChangeScript.java:156)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException

Use dictionary access "subscript" syntax (self.custom['active_calls']) to refer to properties, rather than named attribute access. The property selector should help you with this.

1 Like

That seems to let up the error. Do you mean to say I should refer to all properties that way or just the array? The property selector added the values the way they are added in my original code.

Honestly, I work in Perspective so infrequently that I just thought it was wrong. I kinda prefer the string subscript access anyways (since it's more clear to me that you're effectively retrieving items from a dictionary-like object and it has no issues with key escaping), but it's probably the fact that you changed the script at all that fixed it, rather than the specific changes you made.

might also be another gotcha from this:

calls = self.custom.active_calls

@pbg See this thread:

1 Like

I think I spoke too soon, now I just get a different error. I mean, the code still runs and there's no errors thrown outside of the designer so maybe I could leave it.

 File "<function:valueChanged>", line 3, in valueChanged
KeyError: 'active_calls'

Any chance there's a trailing space or something else on your key?

No there isn't, to me that error is weird since it still reads whatever is in active_calls anyways.

Is that property set to persistent? Any chance your event is running before the active_calls property is written the first time?

1 Like

The active_calls property is continuously getting data from a query tag. The default is always just value in designer unless otherwise specified.

Except for when the view is first loaded. If the property change script executes prior to the active_calls property being added, you will get a key error.

Try setting the active_calls property to be persistent, right now it is not, and see if that eliminates your error.

2 Likes

OH, I understand. Did that and so far no errors, thank you!