Skip to content
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

Properly handle non-unique id_strings #2049

Merged
merged 1 commit into from
Nov 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions kpi/deployment_backends/kobocat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ def timestamp(self):
def xform_id_string(self):
return self.asset._deployment_data.get('backend_response', {}).get('id_string')

@property
def xform_id(self):
pk = self.asset._deployment_data.get('backend_response', {}).get('formid')
xform = _models.XForm.objects.filter(pk=pk).only(
'user__username', 'id_string').first()
if not (xform.user.username == self.asset.owner.username and
xform.id_string == self.xform_id_string):
raise Exception('Deployment links to an unexpected KoBoCAT XForm')
return pk

@property
def mongo_userform_id(self):
return '{}_{}'.format(self.asset.owner.username, self.xform_id_string)
Expand Down Expand Up @@ -524,7 +534,7 @@ def __get_submissions_in_json(self, instances_ids=[]):
:return: generator<JSON>
"""
query = {
"_xform_id_string": self.asset.uid,
"_userform_id": self.mongo_userform_id,
"_deleted_at": {"$exists": False}
}

Expand All @@ -547,8 +557,9 @@ def __get_submissions_in_xml(self, instances_ids=[]):
:return: list<XML>
"""
queryset = _models.Instance.objects.filter(
xform__id_string=self.asset.uid,
deleted_at=None)
xform_id=self.xform_id,
deleted_at=None
)

if len(instances_ids) > 0:
queryset = queryset.filter(id__in=instances_ids)
Expand Down