[IGN-15057]system.util.queryStatus doesn't return AlarmQueryResult

From the docs we're told that system.util.queryStatus() returns AlarmQueryResult see here

When I run it in the design console I get this:

#Pull all alarms
alarms = system.alarm.queryStatus(state=["ActiveUnacked", "ActiveAcked"], source=["*AJAX Alarm*"])
type(alarms)
alarms.getDataset()

# I get this
>>> 
<type 'java.util.Collections$UnmodifiableRandomAccessList'> # not AlarmQueryResult!!!
Traceback (most recent call last):
  File "<input>", line 4, in <module>
AttributeError: 'java.util.Collections$UnmodifiableRandomAccessList' object has no attribute 'getDataset'
>>>

Am I missing something? I need to turn the alarms into a dataset

I'm on 8.3.1

This is a bug caused by some "under the hood" changes from 8.3. We're tracking it internally at a fairly high priority - it'll likely be fixed in 8.3.4 or shortly therafter.

In the meantime, you could try this as a workaround:

from com.inductiveautomation.ignition.common.alarming.query import AlarmQueryResultImpl

def datasetFromAlarms(alarms, historical=False):
		inner = AlarmQueryResultImpl(historical) # pass True if using queryJournal
		inner.extend(alarms)
		return inner.dataset

alarms = system.alarm.queryStatus(state=["ActiveUnacked", "ActiveAcked"])
ds = datasetFromAlarms(alarms)
2 Likes

Great! thanks for the workaround

Running into this same issue on 8.3.2. When I run the workaround in the Script Console I’m getting a ClassCastException. Something obvious I’m doing wrong?

Java Traceback
Traceback (most recent call last):
  File "<input>", line 4, in <module>
	at com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResultImpl.buildFrom(AlarmQueryResultImpl.java:60)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: java.lang.ClassCastException: class com.inductiveautomation.ignition.common.alarming.BasicAlarmEvent cannot be cast to class com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResult (com.inductiveautomation.ignition.common.alarming.BasicAlarmEvent and com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResult are in unnamed module of loader java.net.URLClassLoader @124d25a0)

	at org.python.core.Py.JavaError(Py.java:545)
	at org.python.core.Py.JavaError(Py.java:536)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)
	at org.python.core.PyObject.__call__(PyObject.java:461)
	at org.python.core.PyObject.__call__(PyObject.java:465)
	at org.python.pycode._pyx125.f$0(<input>:5)
	at org.python.pycode._pyx125.call_function(<input>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at org.python.core.Py.exec(Py.java:1747)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)
	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.desktop/javax.swing.SwingWorker.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 java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: class com.inductiveautomation.ignition.common.alarming.BasicAlarmEvent cannot be cast to class com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResult (com.inductiveautomation.ignition.common.alarming.BasicAlarmEvent and com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResult are in unnamed module of loader java.net.URLClassLoader @124d25a0)
	at com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResultImpl.buildFrom(AlarmQueryResultImpl.java:60)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
	... 19 more
Traceback (most recent call last):
  File "<input>", line 4, in <module>
	at com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResultImpl.buildFrom(AlarmQueryResultImpl.java:60)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: java.lang.ClassCastException: class com.inductiveautomation.ignition.common.alarming.BasicAlarmEvent cannot be cast to class com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResult (com.inductiveautomation.ignition.common.alarming.BasicAlarmEvent and com.inductiveautomation.ignition.common.alarming.query.AlarmQueryResult are in unnamed module of loader java.net.URLClassLoader @124d25a0)

Test Code
from com.inductiveautomation.ignition.common.alarming.query import AlarmQueryResultImpl

alarms = system.alarm.queryStatus(state=["ActiveUnacked", "ActiveAcked"])
AlarmQueryResultImpl.buildFrom(alarms)
ds = alarms.getDataset()

You'll need to query your own journal in the source keyword argument

you haven't handed your query a source yet

My bad, my (untested) workaround was flawed because I misunderstood what the 'buildFrom' method was for.

Try this (original post updated as well):

from com.inductiveautomation.ignition.common.alarming.query import AlarmQueryResultImpl

def datasetFromAlarms(alarms, historical=False):
		inner = AlarmQueryResultImpl(historical) # pass True if using queryJournal
		inner.extend(alarms)
		return inner.dataset

alarms = system.alarm.queryStatus(state=["ActiveUnacked", "ActiveAcked"])
ds = datasetFromAlarms(alarms)
1 Like

That did the trick - thanks for the fast fix!

1 Like