Skip to content

Commit

Permalink
Return 0 when getting the submission count…
Browse files Browse the repository at this point in the history
of an invalid/not existing XForm
  • Loading branch information
noliveleger committed Nov 17, 2022
1 parent e530340 commit 3e12add
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions kpi/deployment_backends/kobocat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from kpi.exceptions import (
AttachmentNotFoundException,
InvalidXFormException,
InvalidXPathException,
SubmissionIntegrityError,
SubmissionNotFoundException,
Expand Down Expand Up @@ -1049,7 +1050,10 @@ def set_validation_statuses(self, user: 'auth.User', data: dict) -> dict:

@property
def submission_count(self):
return self.xform.num_of_submissions
try:
return self.xform.num_of_submissions
except InvalidXFormException:
return 0

@property
def submission_list_url(self):
Expand Down Expand Up @@ -1167,9 +1171,12 @@ def xform(self):
) # Avoid extra query to validate username below
.first()
)
if not (xform.user.username == self.asset.owner.username and
xform.id_string == self.xform_id_string):
raise Exception(
if not (
xform
and xform.user.username == self.asset.owner.username
and xform.id_string == self.xform_id_string
):
raise InvalidXFormException(
'Deployment links to an unexpected KoBoCAT XForm')
setattr(self, '_xform', xform)

Expand Down
4 changes: 4 additions & 0 deletions kpi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class InvalidSearchException(exceptions.APIException):
default_code = 'invalid_search'


class InvalidXFormException(Exception):
pass


class InvalidXPathException(Exception):
pass

Expand Down

0 comments on commit 3e12add

Please sign in to comment.