From d2f084e60915d09ffda9b6e8b7efd435fbf2d539 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 20 Jan 2022 10:30:39 +0100 Subject: [PATCH] dataviz: avoid crash in spooler if cell was deleted (#60857) --- combo/utils/spooler.py | 5 ++++- tests/test_dataviz.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/combo/utils/spooler.py b/combo/utils/spooler.py index 179e0868..347cdc58 100644 --- a/combo/utils/spooler.py +++ b/combo/utils/spooler.py @@ -97,5 +97,8 @@ def refresh_statistics_list(): def refresh_statistics_data(cell_pk): from combo.apps.dataviz.models import ChartNgCell - cell = ChartNgCell.objects.get(pk=cell_pk) + try: + cell = ChartNgCell.objects.get(pk=cell_pk) + except ChartNgCell.DoesNotExist: + return cell.get_statistic_data(invalidate_cache=True) diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 79f3dac6..afaaaebc 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -12,6 +12,7 @@ from requests.exceptions import HTTPError from combo.apps.dataviz.models import ChartFiltersCell, ChartNgCell, Gauge, Statistic, UnsupportedDataSet from combo.data.models import Page, ValidityInfo +from combo.utils.spooler import refresh_statistics_data from .test_public import login @@ -1922,3 +1923,21 @@ def test_chartng_cell_api_view_get_parameters(app, normal_user, new_api_statisti resp = app.get(location + '?time_range_start=xxx') assert 'Wrong parameters' in resp.text assert len(new_api_mock.call['requests']) == 5 + + +@with_httmock(new_api_mock) +def test_spooler_refresh_statistics_data(new_api_statistics): + page = Page.objects.create(title='One', slug='index') + cell = ChartNgCell(page=page, order=1, placeholder='content') + cell.statistic = Statistic.objects.get(slug='one-serie') + cell.save() + + refresh_statistics_data(cell.pk) + len(new_api_mock.call['requests']) == 1 + + refresh_statistics_data(cell.pk) + len(new_api_mock.call['requests']) == 2 + + ChartNgCell.objects.all().delete() + refresh_statistics_data(cell.pk) + len(new_api_mock.call['requests']) == 2 -- 2.30.2