diff --git a/kobo/apps/subsequences/tests/test_submission_stream.py b/kobo/apps/subsequences/tests/test_submission_stream.py index 689ece4c0f..4542d603e1 100644 --- a/kobo/apps/subsequences/tests/test_submission_stream.py +++ b/kobo/apps/subsequences/tests/test_submission_stream.py @@ -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([]) diff --git a/kobo/apps/subsequences/utils/__init__.py b/kobo/apps/subsequences/utils/__init__.py index 7703fc1905..bddf773004 100644 --- a/kobo/apps/subsequences/utils/__init__.py +++ b/kobo/apps/subsequences/utils/__init__.py @@ -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']