Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

576: fix _count suffix name clash with repeats targeting another item #674

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

lindsay-stevens
Copy link
Contributor

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:

  • included test cases for core behavior and edge cases in tests
  • run nosetests and verified all tests pass
  • run black pyxform tests to format code
  • verified that any code or assets from external sources are properly credited in comments

- 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").
- As described in XLSForm#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.
- for future reference, this code 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).
- adds new condition to existing logic, where if the expression parses
  to a single pyxform reference, then the item injection is skipped.
Copy link
Contributor

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@lognaturel lognaturel merged commit 7aa346e into XLSForm:master Dec 1, 2023
10 checks passed
@lindsay-stevens lindsay-stevens deleted the pyxform-576 branch December 4, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of _count in variable name results in duplicate survey element error
2 participants