Description:
I am encountering an issue with the format of the data rows in an Ignition script. Specifically, the script is receiving rows in a format that is not a standard dictionary but an ObjectWrapper
. This is causing errors when trying to process and save the data.
Error Message:
Unexpected row format (not a dictionary): <type 'com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ObjectWrapper'>: <ObjectWrapper>: {u'BrassTag_Desc': u'far', u'BrassTag': u'8900'}
Script Details:
The script aims to process data from a Table component and save each row to a database. Here's a snippet of the relevant code:
def runAction(self, event):
# Get the logger instance
logger = system.util.getLogger("BrassTag_Save")
try:
# Get the data from the Table component
tbl = self.getSibling("Table").props.data
# Ensure tbl is not None
if tbl is None:
logger.error("Table data is None. Aborting save operation.")
return
# Convert ObjectWrapper to list of dictionaries if needed
if hasattr(tbl, 'value'):
tbl = tbl.value
# Handle the case where there might not be enough rows
if len(tbl) < 2:
lastBrassTag = None
logger.info("Not enough rows to determine lastBrassTag.")
else:
lastBrassTag = tbl[-2].get("BrassTag", None)
logger.info("Last BrassTag: {}".format(lastBrassTag))
# Run the Named Query to save each row in tbl
for row in tbl:
# Convert ObjectWrapper to dictionary if needed
if hasattr(row, 'value'):
row = row.value
# Check if the row is a dictionary
if isinstance(row, dict):
brass_tag = row.get("BrassTag")
brass_tag_desc = row.get("BrassTag_Desc")
if brass_tag:
system.db.runNamedQuery("Query_BrassTag_Insert",
{"BrassTag": brass_tag,
"BrassTag_Desc": brass_tag_desc,
"user": self.session.props.auth.user.userName})
logger.info("Saved BrassTag: {}, BrassTag_Desc: {}".format(brass_tag, brass_tag_desc))
else:
logger.error("Row missing 'BrassTag' key or 'BrassTag' is empty: {}".format(row))
else:
# Log the type and content of row for debugging
logger.error("Unexpected row format (not a dictionary): {}: {}".format(type(row), row))
# Clear the Table data after saving
self.getSibling("Table").props.data = []
logger.info("Cleared Table data after saving.")
except Exception as e:
logger.error("Error during BrassTag save operation: {}".format(e))
Issue Details:
- Writing some data from a "Table" to database
- Expected Format: Dictionary
- Actual Format:
ObjectWrapper
with dictionary-like content - Example Row:
{u'BrassTag_Desc': u'far', u'BrassTag': u'8900'}
Steps Taken:
- Checked if
tbl
androw
areObjectWrapper
instances and attempted conversion usingrow.value
. - Verified that
tbl
androw
should be dictionaries.
Request for Help:
- How can I handle
ObjectWrapper
instances correctly to ensure they are processed as dictionaries? - Is there a different method to convert or extract data from
ObjectWrapper
in Ignition?
Thank you for your assistance.