dataviz: do not crash on missing statistic url (#54862)

This commit is contained in:
Valentin Deniaud 2021-06-30 10:28:19 +02:00
parent ce5d2fbfca
commit dbc0fee3ad
3 changed files with 17 additions and 2 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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 '<td>18</td>' 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):