Projet

Général

Profil

0001-dataviz-avoid-crash-in-spooler-if-cell-was-deleted-6.patch

Valentin Deniaud, 20 janvier 2022 10:54

Télécharger (2,16 ko)

Voir les différences:

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(-)
combo/utils/spooler.py
97 97
def refresh_statistics_data(cell_pk):
98 98
    from combo.apps.dataviz.models import ChartNgCell
99 99

  
100
    cell = ChartNgCell.objects.get(pk=cell_pk)
100
    try:
101
        cell = ChartNgCell.objects.get(pk=cell_pk)
102
    except ChartNgCell.DoesNotExist:
103
        return
101 104
    cell.get_statistic_data(invalidate_cache=True)
tests/test_dataviz.py
12 12

  
13 13
from combo.apps.dataviz.models import ChartFiltersCell, ChartNgCell, Gauge, Statistic, UnsupportedDataSet
14 14
from combo.data.models import Page, ValidityInfo
15
from combo.utils.spooler import refresh_statistics_data
15 16

  
16 17
from .test_public import login
17 18

  
......
1922 1923
    resp = app.get(location + '?time_range_start=xxx')
1923 1924
    assert 'Wrong parameters' in resp.text
1924 1925
    assert len(new_api_mock.call['requests']) == 5
1926

  
1927

  
1928
@with_httmock(new_api_mock)
1929
def test_spooler_refresh_statistics_data(new_api_statistics):
1930
    page = Page.objects.create(title='One', slug='index')
1931
    cell = ChartNgCell(page=page, order=1, placeholder='content')
1932
    cell.statistic = Statistic.objects.get(slug='one-serie')
1933
    cell.save()
1934

  
1935
    refresh_statistics_data(cell.pk)
1936
    len(new_api_mock.call['requests']) == 1
1937

  
1938
    refresh_statistics_data(cell.pk)
1939
    len(new_api_mock.call['requests']) == 2
1940

  
1941
    ChartNgCell.objects.all().delete()
1942
    refresh_statistics_data(cell.pk)
1943
    len(new_api_mock.call['requests']) == 2
1925
-