Repository navigation
894: References in triggered calculations resolve relative to the trigger instead of the target - #896
Conversation
- repro for pyxform/XLSForm#894 and similar cases where the source is in the lowest common ancestor repeat, and nested inside a repeat. In all cases the @value path is relative to itself, but the path should be relative to the source element "s".
- The ODK spec doesn't seem to explicitly say what the evaluation context for a setvalue should be, but in practice (according to pyxform/XLSForm#894), Collect and Web Forms use the "ref" path context. - The ODK spec references the XForms 1.0 spec, which says in "4.3.6 The xforms-recalculate Event" that when recalculating the form, "the XPath expression is evaluated in the context of the instance node whose value or model item property is associated with the compute". This is somewhat ambiguous as to what "associated with" means, but section "10.1.9 The setvalue Element" is defined as "This action explicitly sets the value of the specified instance data node" and the "value" attribute is defined as: "Optional XPath expression to evaluate, with the result stored in the selected instance data node". Also, section "3.2.3 Single-Node Binding Attributes" prefaces the "ref" attribute definition with "The following attributes define a binding between a form control or an action and an instance data node defined by an XPath expression". Which together suggest that the "setvalue" attributes define "associated with", rather than e.g. the triggering element / document position / parent element of the setvalue element.
- trying to be more explicit/informative about how that value is used
- although setvalue is probably the most common action type for XLSForms, the XForms spec only defines the "value" attribute for the "setvalue" action, and the ODK spec explicitly says that any "value" attribute is ignored for "odk:setgeopoint" and "odk:recordaudio" (which currently are the only supported actions besides "setvalue").
lognaturel
left a comment
There was a problem hiding this comment.
Thank you! Merging in now so it can get exercised. The minor refactoring looks good. I can't imagine value when it's not needed will be missed.
|
Filed getodk/xforms-spec#376 for spec clarification. |
|
@lindsay-stevens @lognaturel You can get this in e.g. those forms: or this one: It is not possible to reproduce it on production server and it worked in the last regression testing
|
|
@srujner Thanks! For the file For the file structure: <outer_c><!-- repeat -->
<c_target/>
<inner_c_count/>
<inner_c><!-- repeat -->
<c_trigger>5</c_trigger>
</inner_c>
</outer_c>old output before this PR (invalid since <setvalue ref="/data/outer_c/c_target" event="xforms-value-changed" value=" ../c_trigger * 2"/>new output after this PR (invalid since <setvalue ref="/data/outer_c/c_target" event="xforms-value-changed" value=" ../inner_c/c_trigger * 2"/>To fix this the calculation in row 23 could use The variable reference(s) in the trigger column doesn't need to do the same filtering, since it is specifying where the setvalue will go in the XForm body. But as a result the calculation might want to use |
|
@lindsay-stevens I'll create a separate issue in web forms for the readonly_3_matrix_en form and error |

Closes #894
Why is this the best possible solution? Were any other approaches considered?
As noted in the commit messages it seems like this is the correct behaviour for the
setvalueelement'svalueattribute.What are the regression risks?
It is a bug fix for a specific use case rather than a behaviour change i.e. triggered calculation inside repeat with non-sibling grouping of the trigger and calculate elements.
As part of the search for relevant code it seemed appropriate to also stop emitting a
valueattribute for non-setvalueelements. The ODK spec says such attributes are ignored but it's possible some form clients expected them, but it seems unlikely. If that looks too risky then the last commit in this PR could be dropped or moved to a different branch.Does this change require updates to documentation? If so, please file an issue here and include the link below.
To me, the setvalue value evaluation context is important enough to clarify in the ODK spec, but maybe it's very obvious?
Before submitting this PR, please make sure you have:
testspython -m unittestand verified all tests passruff format pyxform testsandruff check pyxform teststo lint code