Tracing 2.0 JavaScript API error


I am getting a strange error involving the JavaScript when viewing certain samples regardless of whether it is via the primary Sample View, the Client Sample View, or the Batch Sample View. For some samples (seemingly random), they will not show up at all and will prevent ANY samples from displaying in the listing, and I get this error in the browser console:


I have traced the problem to these 2 functions, but am struggling to bridge the call back to Python and determine why this error even occurs, nor am I familiar with any JS tools (yet) that would help solve this.


I am using both a custom Add-On and created the client using the Senaite API, so my best guess at this time is that there exists some hardcoded check for SOME datapoint being sent in the JSON object that is failing.

However, the perplexing thing is that this only occurs for SOME Samples, and it is not obvious which Samples it is happening to.

I realize that this could be affected by our Add-On, and therefore is not necessarily a Senaite bug at this time. However, I have not edited any JavaScript, so I’m mostly looking for assistance is understanding how to diagnose such a generic JavaScript error when the rest of the Python stack isn’t throwing any errors nor warnings. At least some information on tracing the get_json or on_api_error functions would be extremely helpful :pray:.

I tried to delete some of the samples using the .manage_delObjects() function on the client, and noticed that it gives a strange (yet slightly more informative) error that says ERROR:Zope.UnIndex:FieldIndex: unindex_object tried to retrieve set nan from index 'getDistrict' but couldn't. This should not happen.

I then checked with the ‘getDistrict’ index, and sure enough there is some odd behavior.

I get the nan field multiple times which seems odd. However, many of the clients had been added programmatically using the Senaite API, so I’m thinking the JavaScript error may be related to an improper NULL field in the index.

I will continue to investigate, but any help would still be appreciated :pray:

If I were you I’d start with a new client and add samples one at a time checking the listing after each one until it fails. First via the UI and then via the API. The maybe try the same procedure without you addon installed.

1 Like

Thanks @mikemets!

Turns out it was very related to the NaN index for the Clients. Our clients were migrated from Senaite 1.3 to 2.x with the help of a Pandas dataframe. What happened was that all of the clients with an empty ‘District’ field for their Address were assigned NaN values in the dataframe. When using the Senaite API to create new clients in the new site, Plone did an odd behavior of changing the format of the AT field to match the incoming value instead of throwing an error.

The result was that some of our Clients had a Float type District field instead of a String field, and the Senaite.App.Listing JS code did not handle it well…

Solved the issue by re-doing the migration and adding in a keep_default_na = False when importing the data for DataFrame creation. I believe the .fillna() and .replace() functions could be used as well though.