How to debug generic: `Error executing system.db.runPrepQuery` log events

Well, that's your problem. Postgres is throwing an exception because the transaction isn't live. That's either an explicitly created DB transaction you're passing into the system function, an implicitly created one due to your DB connection properties, or an even higher layer one created by Postgres' local configuration.

Don't do that.
Ignition's logging system is rich - collapsing errors to one line each is making your future life harder for no benefit.

Reaching to @pturmel's later.py for the PythonAsJavaException utility class, you can rewrite your snippet for the same end result with less code:

from java.lang import Throwable

def run(self, database=None, tx=None, syntax=None):
	logger = system.util.getLogger("Select Query")

	time = Query.time()
	try:
		logger.mdcPut("queryTime", time)
		query, params = self.describe(syntax)
		logger.infof(
			"%s (%s) db=%s, tx=%s"
			query, params, database, tx
		)
		return system.db.runPrepQuery(query, params, database, tx)
	except Exception as pythonErr:
		logger.error("Python exception encountered", PythonAsJavaException(pythonErr))
	except Throwable as javaErr:
		logger.error("Java exception encountered", javaErr)
	finally:
		logger.mdcRemove("queryTime")

I'd recommend you use Kindling to view Ignition log files. It's a prebuilt desktop application that fully understands our log file format to give you rich presentation.

1 Like