576: fix _count suffix name clash with repeats targeting another item #674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #576
Why is this the best possible solution? Were any other approaches considered?
Given a form with an item named "a_count" that holds the desired repeat count, and a repeat called "a", when pyxform injects an internal item suffixed with "_count" to hold the repeat count for "a", then pyxform emits a duplicate survey element error (2x "a_count"). This PR adds new condition to existing logic, where if the expression parses to a single pyxform reference, then the item injection is skipped.
As described in #435 (case 1), when the repeat count is just a reference to another item, then that item could be used directly, instead of injecting an item with a calculate item, thereby causing a name clash and thus the error. I tried also satisfying #435 case 3 by allowing single number expressions, but a few test failed with "something broke the parser!" which I think would be due to getodk/javarosa#399
For future reference, the section of code in
xls2json.py
around repeats is a bit confusing but the dict structure of json["control"]["jr:count"] is a result of processing in dealias_and_group_headers (repeat_count -> control::jr:count -> dict).What are the regression risks?
ODK Validate seems OK with this, but I have not tested it with Collect or Enketo. If they or any other XForms tool expects there to always be an injected instance item to hold the count, then I expect there would be an error.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No, it's an internal form structure issue, which addresses a user-facing bug.
Before submitting this PR, please make sure you have:
tests
nosetests
and verified all tests passblack pyxform tests
to format code