Skip to content

Commit

Permalink
Report UCR row count on MobileUCRTooLargeException
Browse files Browse the repository at this point in the history
  • Loading branch information
millerdev committed Jun 20, 2024
1 parent eed4e15 commit 77e0fe1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion corehq/apps/app_manager/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,7 @@ class CannotRestoreException(Exception):


class MobileUCRTooLargeException(CannotRestoreException):
pass

def __init__(self, message, row_count):
super().__init__(message)
self.row_count = row_count
14 changes: 10 additions & 4 deletions corehq/apps/app_manager/fixtures/mobile_ucr.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ def __call__(self, restore_state):
]

for provider in providers:
fixtures.extend(provider(restore_state, restore_user, needed_versions, report_configs))
self.report_ucr_row_count(provider.row_count, provider.version, restore_user.domain)
try:
fixtures.extend(provider(restore_state, restore_user, needed_versions, report_configs))
row_count = provider.row_count
except MobileUCRTooLargeException as err:
row_count = err.row_count
self.report_ucr_row_count(row_count, provider.version, restore_user.domain)

return fixtures

Expand Down Expand Up @@ -563,12 +567,14 @@ def get_report_element(
if len(rows) > settings.MAX_MOBILE_UCR_SIZE:
raise MobileUCRTooLargeException(
f"Report {report_config.report_id} row count {len(rows)} exceeds max allowed row count "
f"{settings.MAX_MOBILE_UCR_SIZE}"
f"{settings.MAX_MOBILE_UCR_SIZE}",
row_count=len(rows),
)
if len(rows) + current_row_count > settings.MAX_MOBILE_UCR_SIZE * 2:
raise MobileUCRTooLargeException(
"You are attempting to restore too many mobile reports. Your Mobile UCR Restore Version is set to 1.0."
" Try upgrading to 2.0."
" Try upgrading to 2.0.",
row_count=len(rows) + current_row_count,
)
for row_index, row in enumerate(rows):
row_elements.append(row_to_element(deferred_fields, filter_options_by_field, row, row_index))
Expand Down

0 comments on commit 77e0fe1

Please sign in to comment.