Projet

Général

Profil

0001-dataviz-do-not-crash-on-missing-statistic-url-54862.patch

Valentin Deniaud, 30 juin 2021 10:31

Télécharger (3,1 ko)

Voir les différences:

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(-)
combo/apps/dataviz/models.py
256 256
        if not self.statistic:
257 257
            return
258 258

  
259
        if not self.statistic.url:
260
            self.mark_as_invalid('missing_statistic_url')
261
            return
262

  
259 263
        resp = None
260 264
        try:
261 265
            resp = self.get_statistic_data()
......
268 272

  
269 273
    def get_cell_extra_context(self, context):
270 274
        ctx = super(ChartNgCell, self).get_cell_extra_context(context)
271
        if self.chart_type == 'table' and self.statistic:
275
        if self.chart_type == 'table' and self.statistic and self.statistic.url:
272 276
            try:
273 277
                chart = self.get_chart(raise_if_not_cached=not (context.get('synchronous')))
274 278
            except UnsupportedDataSet:
combo/apps/dataviz/views.py
36 36
        raise PermissionDenied()
37 37
    if not cell.is_visible(user=request.user):
38 38
        raise PermissionDenied()
39
    if not cell.statistic:
39
    if not cell.statistic or not cell.statistic.url:
40 40
        raise Http404('misconfigured cell')
41 41
    error_text = None
42 42
    try:
tests/test_dataviz.py
1045 1045
    # table visualization
1046 1046
    cell.chart_type = 'table'
1047 1047
    cell.save()
1048
    resp = app.get(location)  # populate cache
1048 1049
    resp = app.get('/')
1049 1050
    assert '<td>18</td>' in resp.text
1050 1051

  
......
1054 1055
    resp = app.get(location)
1055 1056
    assert 'not found' in resp.text
1056 1057

  
1058
    cell.statistic.url = ''
1059
    cell.statistic.save()
1060
    resp = app.get(location, status=404)
1061

  
1057 1062

  
1058 1063
@with_httmock(bijoe_mock)
1059 1064
def test_chartng_cell_manager(app, admin_user, statistics):
......
1410 1415
    validity_info = ValidityInfo.objects.latest('pk')
1411 1416
    assert validity_info.invalid_reason_code == 'statistic_data_not_found'
1412 1417

  
1418
    stat.url = ''
1419
    stat.save()
1420
    cell.check_validity()
1421
    validity_info = ValidityInfo.objects.latest('pk')
1422
    assert validity_info.invalid_reason_code == 'missing_statistic_url'
1423

  
1413 1424

  
1414 1425
@with_httmock(new_api_mock)
1415 1426
def test_chartng_cell_new_api_aggregation(new_api_statistics, app, admin_user, nocache):
1416
-