Skip to content

Commit

Permalink
Merge pull request #4143 from kobotoolbox/fix-submission-counter-with…
Browse files Browse the repository at this point in the history
…-no-xform

Fix error "Failed to list assets" when some projects are invalid but still appear in the UI
  • Loading branch information
jnm authored Nov 17, 2022
2 parents e530340 + 3e12add commit 2268bf0
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 2268bf0

Please sign in to comment.