From 1a4c4da1533c87e7174d9e52e911e35b4ebcef0a Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 24 May 2022 14:52:08 +0200 Subject: [PATCH 2/2] dataviz: do not raise error in check_validity (#65615) --- combo/apps/dataviz/models.py | 2 +- tests/test_dataviz.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 077028c7..d7a5340e 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -302,7 +302,7 @@ class ChartNgCell(CellBase): resp = None try: resp = self.get_statistic_data() - except RequestException: + except (RequestException, MissingRequest, MissingVariable): pass self.set_validity_from_url( diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index d8ce9d2e..fbcceb46 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -2114,7 +2114,7 @@ def test_chartng_cell_new_api_filter_params_page_variables_table(new_api_statist def test_dataviz_check_validity(nocache): - page = Page.objects.create(title='One', slug='index') + page = Page.objects.create(title='One', slug='index', extra_variables={'foo': 'bar'}) stat = Statistic.objects.create(url='https://stat.com/stats/1/') cell = ChartNgCell.objects.create(page=page, order=1, placeholder='content', statistic=stat) @@ -2126,6 +2126,17 @@ def test_dataviz_check_validity(nocache): cell.check_validity() assert ValidityInfo.objects.exists() is False + # cell using page variable is valid even if it cannot be evaluated + cell.filter_params = {'test': 'variable:foo'} + cell.save() + + with HTTMock(url_mock): + cell.check_validity() + assert ValidityInfo.objects.exists() is False + + cell.filter_params.clear() + cell.save() + @urlmatch(scheme='https', netloc=r'stat.com', path='/stats/1/') def url_mock2(url, request): return {'content': json.dumps({'data': [], 'err': 1}), 'status_code': 404} -- 2.30.2