OpenClinica / enketo-oc

OpenClinica's fork of the Enketo web forms monorepo
Apache License 2.0
0 stars 1 forks source link

Loading error when loading record without repeat instances #72

Open MartijnR opened 2 years ago

MartijnR commented 2 years ago

Describe the bug I found this bug with an unusual test operation. I may theoretically occur in real life with forms that were generated with old versions of pyxform. The first condition is that the form includes a repeat but that there is no default first instance of the repeat present in the XForm. The second condition is that an existing record is loaded and that that record has no repeat instances.

Screen Shot 2022-07-15 at 1 50 10 PM

To Reproduce Steps to reproduce the behavior. If applicable please include the smallest possible XLSForm or XForm (as zip or link).

  1. Transform this form with an old version of pyxform or remove the first (non-template) repeat instance from the model after transformation to an XForm (i.e. remove <rep><a/></rep>).
  2. Load an instance (edit) view to load record <data><meta><instanceID>uuid:1234</instanceID></meta></data>, e.g. like this:
    curl --user enketorules: -d "server_url=http://localhost:3000&form_id=repeat-relevant&ecid=1&instance=<data><meta><instanceID>uuid:1234</instanceID></meta></data>&instance_id=a" http://localhost:8005/oc/api/v1/instance/edit
  3. See the TypeError: this.form.repeatPathPrefixes is not iterable

Expected behavior For the record to load without errors (and without repeats) as with record <data><rep/><meta><instanceID>uuid:1234</instanceID></meta></data>

Additional context Though old XForms like this will exist, it may not actually be possible for OC to pass a record without repeat instances in which case this bug should not occur.

MartijnR commented 2 years ago

To be clear, I expect this can be closed but thought it would be helpful to have this documented in this issue in case it ever pops up.