Skip to content

Commit

Permalink
Check for total row count across reports for V1 provider
Browse files Browse the repository at this point in the history
  • Loading branch information
gherceg committed Jun 20, 2024
1 parent 7df0a4c commit 1d2170d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions corehq/apps/app_manager/fixtures/mobile_ucr.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _row_to_row_elem(
return row_elem

row_elements, filters_elem = generate_rows_and_filters(
self.report_data_cache, report_config, restore_user, _row_to_row_elem
self.report_data_cache, report_config, restore_user, _row_to_row_elem, self.row_count
)
# the v1 provider writes all reports to one fixture, so the "effective" row_count is the sum of every
# report's row_count
Expand Down Expand Up @@ -489,11 +489,14 @@ def _format_last_sync_time(restore_user, sync_time=None):
return ServerTime(sync_time).user_time(timezone).done().isoformat()


def generate_rows_and_filters(report_data_cache, report_config, restore_user, row_to_element):
def generate_rows_and_filters(
report_data_cache, report_config, restore_user, row_to_element, current_row_count=None
):
"""Generate restore row and filter elements
:param row_to_element: function (
deferred_fields, filter_options_by_field, row, index, is_total_row
) -> row_element
:param current_row_count: optional int used by v1 reports provider to accumulate row count across all reports
"""
report, data_source = report_data_cache.get_report_and_datasource(report_config.report_id)

Expand Down Expand Up @@ -534,11 +537,19 @@ def generate_rows_and_filters(report_data_cache, report_config, restore_user, ro


def get_report_element(
report_data_cache, report_config, data_source, deferred_fields, filter_options_by_field, row_to_element):
report_data_cache,
report_config,
data_source,
deferred_fields,
filter_options_by_field,
row_to_element,
current_row_count=None,
):
"""
:param row_to_element: function (
deferred_fields, filter_options_by_field, row, index, is_total_row
) -> row_element
:param current_row_count: optional int used by v1 reports provider to accumulate row count across all reports
"""
if data_source.has_total_row:
total_row_calculator = IterativeTotalRowCalculator(data_source)
Expand All @@ -553,6 +564,11 @@ def get_report_element(
f"Report {report_config.report_id} row count {len(rows)} exceeds max allowed row count "
f"{settings.MAX_MOBILE_UCR_SIZE}"
)
if current_row_count and 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."
)
for row_index, row in enumerate(rows):
row_elements.append(row_to_element(deferred_fields, filter_options_by_field, row, row_index))
total_row_calculator.update_totals(row)
Expand Down

0 comments on commit 1d2170d

Please sign in to comment.