754: fix 'NoneType is not iterable' error for group with no children#787
Merged
Conversation
- groups usually have child elements, and if they don't (as shown in test_groups.py) ODK Validate will raise an error, so the Section class now sets a default list since most of the time a list will be created anyway. Moved children-related class methods from SurveyElement to Section since the latter is the type using them. - interestingly the same kind of error does not occur for repeats, as shown in test_repeat.py. - empty groups may also be a problem in form clients as follows but this behaviour can't be tested here: - enketo with setting `style` = `theme-grid` but no group label - collect group with no visible items due to all being relevant=false
- while it makes the git history a little harder to navigate, this should make it easier to understand test coverage for these elements
- there's no empty group error expected for repeats but in any case an error can't be raised by validate if it's not run on the xform
lognaturel
approved these changes
Dec 9, 2025
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #754
Also added test to document behaviour with repeats where a similar 'empty group' error is not raised
Also tidies up group/repeat related tests to make test coverage clearer
Why is this the best possible solution? Were any other approaches considered?
In
section.py, considered addingif self.children is not Nonebranches where necessary, but usually a Section subclass will have child elements so instead a default list is created in the__init__method.What are the regression risks?
If an external library subclasses SurveyElement but expects the moved children-related methods to be there, they would need to copy them over to their own implementation, or use Section as a parent class instead.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No just a bug fix.
Before submitting this PR, please make sure you have:
testspython -m unittestand verified all tests passruff format pyxform testsandruff check pyxform teststo lint code