XLSForm/pyxform

Entity update forms currently must have the entity list attached

Closed this issue · 1 comments

Problem description

When an XLSForm specifies an entity update, an expression to get the existing entity's baseVersion is generated by pyxform. This expression reads from the entity list that the update targets, assuming that it will always be attached. However, there are useful forms to write that could update an entity without having the entity list attached. In particular, when using barcode ids offline to identify entities, there may not be any need to query the entity list.

The issue stems from Validate because JavaRosa specifically detects instance calls on instance names that aren't defined:

Error: ODK Validate Errors:
>> Something broke the parser. See above for a hint.
Error evaluating field 'baseVersion' (${meta}[1]/entity[1]/@baseVersion): The problem was located in Calculate expression for ${entity}/@baseVersion
XPath evaluation: Instance referenced by instance(participants)/root/item/__version does not exist
Caused by: org.javarosa.xpath.XPathMissingInstanceException: The problem was located in Calculate expression for ${entity}/@baseVersion
XPath evaluation: Instance referenced by instance(participants)/root/item/__version does not exist

Steps to reproduce the problem

Try to convert a form like https://docs.google.com/spreadsheets/d/1ALphkUqVgXGBV8jmCx0wohHDXknH1q3BHFQOj16IuA4/edit#gid=1068911091

Expected behavior

Some ideas for what we could do when the entity list isn't attached:

  • set the baseVersion to 0. That will never exist because versions are 1-based and so there will always be a conflict detected
  • set the baseVersion to 1. Submissions from forms that are only ever supposed to make one update would never get conflicts but multiple updates would result in conflicts

Other information

This kind of form is only practical if the barcodes are created from entities that are already registered. Maybe it's not a hugely useful/common scenario so we could wait until it comes up to address it. It may become more practical once bulk upload is more approachable.

Closing for now since there isn't an obvious action to take.