Perspective property query binding transform executing when value is NoneType

I am working on some perspective views with some production data charts (using the free Embr Charts module) which get populated with data from a SQL database. To get this to work, I added a custom property with a query binding which returns a dataset and script transform to interpret and format the data for the charts. Since some of the charts are used on multiple views, I defined functions in gateway scripts which interpret and format the data, which are called by transforms on property bindings.

I’m having an issue on a couple of my charts where it seems like the transform script is running before the query is complete. At first I was thinking this was an issue with the pie chart from Embr Charts, but after adding some logging I think that isn’t the issue. I added some logging via system.perspective.sendMessage so that I can see what is happening from the client (behavior is different/harder to reproduce in designer). I am writing to the log when navigation changes to a different view. I also added a property change script on the property with the query binding and transform which logs currentValue.getQuality(). A section of this log is at the bottom of this post. What I am seeing is that when I navigate to the display titled “Defects” (which is having this issue) about 90% of the time, the property change script will run twice. The first time it will say that the quality is bad because 'NoneType' object has no attribute 'getRowCount'. One of the first things that is done in the function called by the transform script is getting the row count from the dataset that the query returns, so it seems like this is running before getting the data from the query. After about 290ms the property change script runs again and logs the quality as good. When this happens, the chart shows a warning icon with the text “Component Error” (tooltip says Cannot read properties of null (reading ‘length’). The other 10% of the time the property change script only shows up in the log a single time with “Good” quality and the chart displays properly.

I tried removing the transform so that the property binding is only running the query. Then I creating a second custom property with an expression structure binding (with “Wait On All” enabled) pointing to the first property and calling the transform script. I thought this might do essentially the same thing but force the second binding to wait for the dataset to be populated, but it did exactly the same thing.

Am I doing something incorrectly? Is the problem that I’m calling a function defined in the gateway scripts from a property binding?

01/21 08:25:40.743: Defect chart data quality: Good
01/21 08:25:40.670: Next view: Defects
01/21 08:25:39.077: Next view: Time
01/21 08:25:37.812: Defect chart data quality: Good
01/21 08:25:37.524: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:37.492: Next view: Defects
01/21 08:25:36.058: Next view: Time
01/21 08:25:35.014: Defect chart data quality: Good
01/21 08:25:34.721: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:34.693: Next view: Defects
01/21 08:25:33.243: Next view: Time
01/21 08:25:31.651: Defect chart data quality: Good
01/21 08:25:31.351: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:31.315: Next view: Defects
01/21 08:25:29.531: Next view: Time
01/21 08:25:28.297: Defect chart data quality: Good
01/21 08:25:28.008: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:27.982: Next view: Defects
01/21 08:25:26.034: Next view: Time
01/21 08:25:24.327: Defect chart data quality: Good
01/21 08:25:24.027: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:23.972: Next view: Defects
01/21 08:25:21.744: Next view: Time
01/21 08:25:18.579: Defect chart data quality: Good
01/21 08:25:18.290: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:18.252: Next view: Defects
01/21 08:25:16.355: Next view: Time
01/21 08:25:14.944: Defect chart data quality: Good
01/21 08:25:14.654: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:14.614: Next view: Defects
01/21 08:25:12.910: Next view: Time
01/21 08:25:10.812: Next view: PPM
01/21 08:25:09.069: Next view: Time
01/21 08:25:05.498: Defect chart data quality: Good
01/21 08:25:05.206: Defect chart data quality: Error_ScriptEval("Traceback (most recent call last):
  File "<transform>", line 2, in transform
  File "<module:BinData>", line 740, in unitDefectsChartsCombined
  File "<module:BinData>", line 848, in PieChart_Unit_Defects
AttributeError: 'NoneType' object has no attribute 'getRowCount'
")
01/21 08:25:05.179: Next view: Defects
01/21 08:25:04.246: Next view: Time
01/21 08:25:03.134: Next view: PPM
01/21 08:25:00.487: Next view: Time
01/21 08:24:54.733: Defect chart data quality: Good
01/21 08:24:54.680: Next view: Defects
01/21 08:24:52.494: Next view: Time

Is there error only occurring on page load? If so, it's initially giving the binding a "None" value, which is then trying to run thru the Transform. You need to either persist a "good" set of data, or tweak your transform so it recognizes the empty DS and stops trying to go further. Then once the actual binding fires, it should run thru correctly.

1 Like

Are you suggesting something like this?

if value is None:
    return dictOfBlankData
else:
    return gatewayScript(value)

Edit: I tried this and it actually made the component error appear on the bar chart as well as the pie chart. I also noticed that in a client when I resize the split container that the pie chart is in, the component error goes away and the chart is rendered properly. Almost like the property value is correct, but the chart isn’t redrawn. Calling refreshBinding on the query binding doesn’t seem to fix it.

Also worth noting, my transform script is returning a dictionary containing 4 dictionaries. The 4 dictionaries each contain the data for 1 of the 4 charts in the view. Only 1 of the 4 charts is having problems, the other 3 work every time.

Edit 2: I tried setting the property with the query binding and transform as persistent and saving it with a good value. The behavior remains unchanged. I also noticed when I open the GUI for configuring the binding, if I have binding preview enabled, initially under “Query” is shows “Dataset[1850 rows, 141 cols]”, then it briefly shows, “Error_Exception”, then it goes back to showing “Dataset[1850 rows, 141 cols]”. This seems very similar to what is happening when navigating to this view.