Skip to content

Commit

Permalink
Merge pull request #5029 from kobotoolbox/duplicate-submission-uuid-bug
Browse files Browse the repository at this point in the history
Fix bug blocking qualitative analysis feature with "unhashable type dict" error
  • Loading branch information
noliveleger authored Jul 30, 2024
2 parents 6d3db49 + 762fd9e commit 2ef24d5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions kobo/apps/subsequences/tests/test_submission_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,47 @@ def mock_submission_stream():
assert '_supplementalDetails' in output[0]
assert '_supplementalDetails' in output[1]
# test other things?

def test_stream_with_extras_handles_duplicated_submission_uuids(self):
# Define submission data with duplicated UUIDs
submissions = [
{
'What_s_your_name': 'Ed',
'Tell_me_a_story': 'ed-18_6_24.ogg',
'meta/instanceID': 'uuid:1c05898e-b43c-491d-814c-79595eb84e81',
'_uuid': '1c05898e-b43c-491d-814c-79595eb84e81',
},
{
'What_s_your_name': 'Ed',
'Tell_me_a_story': 'ed-18_6_44.ogg',
'meta/instanceID': 'uuid:1c05898e-b43c-491d-814c-79595eb84e81',
'_uuid': '1c05898e-b43c-491d-814c-79595eb84e81',
},
]
self.asset.deployment.mock_submissions(submissions)

# Process submissions with extras
output = list(
stream_with_extras(
self.asset.deployment.get_submissions(user=self.asset.owner),
self.asset,
)
)

# Make sure that uuid values for single or multiple choice qualitative
# analysis questions are kept as strings and not mutated
for submission in output:
supplemental_details = submission['_supplementalDetails']
for qual_response in supplemental_details['Tell_me_a_story']['qual']:
if qual_response['type'] not in [
'qual_select_one',
'qual_select_multiple',
]:
# question is not a single or multiple choice one
continue

for v in qual_response['val']:
assert isinstance(v['uuid'], str)

# Clear all mocked submissions to avoid duplicate submission errors
self.asset.deployment.mock_submissions([])
2 changes: 1 addition & 1 deletion kobo/apps/subsequences/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def stream_with_extras(submission_stream, asset):
uuid = submission[SUBMISSION_UUID_FIELD]
else:
uuid = submission['_uuid']
all_supplemental_details = extras.get(uuid, {})
all_supplemental_details = deepcopy(extras.get(uuid, {}))
for qpath, supplemental_details in all_supplemental_details.items():
try:
all_qual_responses = supplemental_details['qual']
Expand Down

0 comments on commit 2ef24d5

Please sign in to comment.