From d49c607de898c05c550a78c04bafd7db23dd2511 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 30 Jun 2021 10:28:19 +0200 Subject: [PATCH] dataviz: do not crash on missing statistic url (#54862) --- combo/apps/dataviz/models.py | 6 +++++- combo/apps/dataviz/views.py | 2 +- tests/test_dataviz.py | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index fc397ca5..3b98e79a 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -256,6 +256,10 @@ class ChartNgCell(CellBase): if not self.statistic: return + if not self.statistic.url: + self.mark_as_invalid('missing_statistic_url') + return + resp = None try: resp = self.get_statistic_data() @@ -268,7 +272,7 @@ class ChartNgCell(CellBase): def get_cell_extra_context(self, context): ctx = super(ChartNgCell, self).get_cell_extra_context(context) - if self.chart_type == 'table' and self.statistic: + if self.chart_type == 'table' and self.statistic and self.statistic.url: try: chart = self.get_chart(raise_if_not_cached=not (context.get('synchronous'))) except UnsupportedDataSet: diff --git a/combo/apps/dataviz/views.py b/combo/apps/dataviz/views.py index 7d4cb55b..af811b2a 100644 --- a/combo/apps/dataviz/views.py +++ b/combo/apps/dataviz/views.py @@ -36,7 +36,7 @@ def dataviz_graph(request, *args, **kwargs): raise PermissionDenied() if not cell.is_visible(user=request.user): raise PermissionDenied() - if not cell.statistic: + if not cell.statistic or not cell.statistic.url: raise Http404('misconfigured cell') error_text = None try: diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 7d2a3f30..4099e342 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -1045,6 +1045,7 @@ def test_chartng_cell_view_new_api(app, normal_user, new_api_statistics): # table visualization cell.chart_type = 'table' cell.save() + resp = app.get(location) # populate cache resp = app.get('/') assert '18' in resp.text @@ -1054,6 +1055,10 @@ def test_chartng_cell_view_new_api(app, normal_user, new_api_statistics): resp = app.get(location) assert 'not found' in resp.text + cell.statistic.url = '' + cell.statistic.save() + resp = app.get(location, status=404) + @with_httmock(bijoe_mock) def test_chartng_cell_manager(app, admin_user, statistics): @@ -1410,6 +1415,12 @@ def test_dataviz_check_validity(nocache): validity_info = ValidityInfo.objects.latest('pk') assert validity_info.invalid_reason_code == 'statistic_data_not_found' + stat.url = '' + stat.save() + cell.check_validity() + validity_info = ValidityInfo.objects.latest('pk') + assert validity_info.invalid_reason_code == 'missing_statistic_url' + @with_httmock(new_api_mock) def test_chartng_cell_new_api_aggregation(new_api_statistics, app, admin_user, nocache): -- 2.20.1