-
Notifications
You must be signed in to change notification settings - Fork 138
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
603: (secondary instances) fix or_other + translations + group or repeat #650
603: (secondary instances) fix or_other + translations + group or repeat #650
Conversation
- in _create_section_from_dict, the context is the nearest "section" which can be a survey, group, or repeat. When it's not the survey, the survey-level choices dict isn't directly available. So this is now tracked by the builder as a class-level object. - added tests for groups, repeats, groups-in-groups, repeats-in-groups.
- standardise to help avoid misspelling / refactoring issues in future
Ah, very interesting.
Did you consider throwing an error in this case and saying
Yikes! I'd always assumed that |
@lognaturel The default language gets This PR is a bug fix because it's restoring previous functionality that was broken during the secondary instances PR - it's not an intentional deprecation. So throwing an error didn't seem right since a deprecation should have some kind of notice ahead of release. Similarly, adding a warning is sort of a new feature. If you prefer to keep
|
I checked the user form on Enketo and got “Other” for every language, I’m pretty sure. I guess it doesn’t matter, it’s bad either way.
True. My thinking is that it’s such a bad result that we really should have been erroring out before. That said, I’m ok with a once-per-form warning with your suggested text. |
- warning is once per form. Re-used missing translations check code to avoid doing the same processing twice. The new check needed the intermediate result of the missing check. - test_validators.py: removed version check for import since supported versions have been above 3.3 for a while.
@lognaturel I added a once-per-form warning when using or_other and translations together. The or_other usage is detected when at least one question uses a it. Translations are detected in the same way as the existing missing translations check (column names from survey or choices), and the or_other check won't fire if the only "language" is the internal default language. To avoid additional processing overhead, the missing translations check code was refactored so that the translation detection result could be re-used for the or_other check (and other checks in future). |
Thank you! I noticed #653 when reviewing but it's not directly related to this PR so we can discuss separately. |
Closes #649
Resolves issue mentioned here.
In _create_section_from_dict, the context is the nearest "section", which can be a survey, group, or repeat. When it's not the survey, the survey-level choices dict isn't directly available. So this is now tracked by the builder as a class-level object.
Why is this the best possible solution? Were any other approaches considered?
It fixes the error, while avoiding changing the API for SurveyElementBuilder, which is exposed at the top level
__init__.py
. An alternative to using a class-level variable would be to pass the survey dict around, but that would change the API.What are the regression risks?
Maybe if library users use a SurveyElementBuilder instance in a weird way (like re-using an instance for multiple surveys, or directly calling private/underscored methods), it might produce odd results. But the main entry point for using this class is
create_survey_element_from_dict
, and the survey's choices dict is copied/written back in that function.Does this change require updates to documentation? If so, please file an issue here and include the link below.
No, but I think fully deprecating
or_other
should happen at some point, since:Similarly, this fix required code specific to "loops" which are a type of group, and it appears to be an undocumented feature - if it is deprecated then all code for it should be removed.
Before submitting this PR, please make sure you have:
tests
nosetests
and verified all tests passblack pyxform tests
to format code