Saving a Batch via Python API

LabKey Support Forum (Inactive)
Saving a Batch via Python API simon buckner  2017-02-20 12:50
Status: Closed
 
Issue: When using the Labkey Python API, I am unable to save a batch, although I am able via the UI. The API follows a different flow that does not seem to be preserving uploaded data.

I downloaded the Python API from here: https://github.com/LabKey/labkey-api-python, and based my script off of this sample: https://github.com/LabKey/labkey-api-python/blob/master/samples/save_batch_example.py

I noticed that the flow for the save_batch() API call begins at SaveAssayBatchAction.java:executeAction(), whereas the UI upload is directed to UploadWizardAction.java:saveExperimentRun(). When uploading from the UI, the batch saves just fine. When uploading from the API, it makes it to TsvDataExchangeHandler.java:_writeRunData(). This line:

dataFiles.addAll(context.getUploadedData().values());

...seems to be giving me trouble. From the UI, the context variable is an instance of AssayRunUploadContext, and uploadedData is an ArrayList<File>. When using the Python API, context is an instance of ModuleRunUploadForm, and uploadedData is an ArrayList<JSONObject>. This does not seem to be valid somewhere in the code, as Python returns the error:

labkey.exceptions.RequestError: '400: runDataUploadedFile not found in assay run properties.'

The uploaded file property is not being set because the uploadedData field is not found/recognized in the context object.

Is this a known issue? If not, is there anything about the Python API I am missing?

Thanks,

Simon
 
 
jeckels responded:  2017-02-20 15:36
Hi Simon,

Does this assay design have a transform script? It may be the combination of API-based insertion and transform script that's causing the problem.

Thanks,
Josh
 
simon buckner responded:  2017-02-21 07:50
Hi Josh,

Removing my transform script allowed the upload to complete. I'm a little confused, because it didn't look like it had reached that point in the code yet. But at least this narrows it down for me; I can focus on debugging my script now.

Thanks a lot!

Simon
 
jeckels responded:  2017-02-21 09:31
Hi Simon,

You may have already discovered this, but the server is expecting there to be a "runDataUploadedFile" property in the runProperties.tsv file after the transform script. Presumably it's not present because your Python script is supplying the data rows as part of the API request instead of as a reference to a data file on disk. This is not a commonly used combination (API-based insertion and transform script), so there may be a gap or two like this, but hopefully you can find an approach that works.

Thanks,
Josh