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.
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
Handle a question whose type changes but name doesn't. #187
base: main
Are you sure you want to change the base?
Handle a question whose type changes but name doesn't. #187
Changes from 12 commits
7fb1ad9
c15fc18
5af7218
9652455
5953cde
cc58e06
f4809a4
dc69313
3985489
a042146
3b0db4d
dc05c1d
50b5a2e
16a896a
d1c5429
f0ddf7d
bd25c51
785ebda
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(self: revise this) i guess this is the expected contextual name, used for comparison not assignment?possible to use the
create_unique_name()
method to avoid hard-coding this here?https://github.com/kobotoolbox/formpack/pull/187/files#diff-7845025cfa4cd9a06d7a4399e1ba9c0bR58
or, maybe
if field.contextual_name.startswith("{}_{}_v".format(
below could be changed to something likeif field.use_unique_name
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jnm: I now remember why I did this comparison this way.
We have
Let's explain:
All fields that are added by
get_fields_for_versions
(because another type has been detected in the latest version) match the patternname
_data_type
_version_id
.version_id
is the same. Data belongs to this field. All other fields with same name will be skipped for this submission.version_id
is not the same, we want to iterate over loop immediately because the datashould be appended to the corresponding field (or column in the export) only - which is a further occurrence of the loop.
The
{}_{}_v
pattern is used to avoid matching another field name.For example:
- Question 1:
restaurant
- Question 2:
restaurant_text
Adding the "_v" in the pattern decreases the risk of matching the wrong field.
Obviously if all these rules are true:
restaurant
has multiple types among versionstext
restaurant_text_v
Export will have data shifted again. The comparison would be a regex to decrease the risk a little bit more.
Something like
_v[\d\w]{21,}
. What do you think?Having this said: Your suggestion to use
create_unique_name
is really good idea.About the idea of
maybe if field.contextual_name.startswith("{}_{}_v".format( below could be changed to something like if field.use_unique_name?
Actually it can't.
In case the form has more than 3 versions and each version contains a question with the same name but 3 different types.
In that case
fields
should be:Let's say, we have 1 submission for each version where value of the question
question
would beanswer
1
2018-12-18 00:00:00
Using
field.use_unique_name
, submission 1 and 2 would be matched with fieldquestion_text_v123456
because both fieldsquestion_text_v123456
andquestion_integer_v234567
haveuse_unique_name
property equalsTrue
. Using the string comparisonsubmission 2
can't be matched withquestion_text_v123456
(because itsversion_id
is not the same)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: everywhere else, this is changed to
contextual_name='%s'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have hesitated between using
self.name
forFormDataDef
or changing the representation string becausecontextual_name
is more related toFormField
than its parent class.Still wondering...