Skip to content

Commit 2268bf0

Browse files
authored
Merge pull request #4143 from kobotoolbox/fix-submission-counter-with-no-xform
Fix error "Failed to list assets" when some projects are invalid but still appear in the UI
2 parents e530340 + 3e12add commit 2268bf0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

kpi/deployment_backends/kobocat_backend.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from kpi.exceptions import (
4141
AttachmentNotFoundException,
42+
InvalidXFormException,
4243
InvalidXPathException,
4344
SubmissionIntegrityError,
4445
SubmissionNotFoundException,
@@ -1049,7 +1050,10 @@ def set_validation_statuses(self, user: 'auth.User', data: dict) -> dict:
10491050

10501051
@property
10511052
def submission_count(self):
1052-
return self.xform.num_of_submissions
1053+
try:
1054+
return self.xform.num_of_submissions
1055+
except InvalidXFormException:
1056+
return 0
10531057

10541058
@property
10551059
def submission_list_url(self):
@@ -1167,9 +1171,12 @@ def xform(self):
11671171
) # Avoid extra query to validate username below
11681172
.first()
11691173
)
1170-
if not (xform.user.username == self.asset.owner.username and
1171-
xform.id_string == self.xform_id_string):
1172-
raise Exception(
1174+
if not (
1175+
xform
1176+
and xform.user.username == self.asset.owner.username
1177+
and xform.id_string == self.xform_id_string
1178+
):
1179+
raise InvalidXFormException(
11731180
'Deployment links to an unexpected KoBoCAT XForm')
11741181
setattr(self, '_xform', xform)
11751182

kpi/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class InvalidSearchException(exceptions.APIException):
7474
default_code = 'invalid_search'
7575

7676

77+
class InvalidXFormException(Exception):
78+
pass
79+
80+
7781
class InvalidXPathException(Exception):
7882
pass
7983

0 commit comments

Comments
 (0)