diff --git a/shared/reports/types.py b/shared/reports/types.py index 418c7b0b..d1e889f2 100644 --- a/shared/reports/types.py +++ b/shared/reports/types.py @@ -223,7 +223,7 @@ def build_from_encoded_data(cls, sessions_array: Union[dict, list]): extra=dict(sessions_array=sessions_array), ) sessions_array["meta"] = { - "session_count": max(sessions_array.keys()) + 1 + "session_count": int(max(sessions_array.keys())) + 1 } meta_info = sessions_array.pop("meta") session_count = meta_info["session_count"] diff --git a/tests/unit/reports/test_types.py b/tests/unit/reports/test_types.py index edb3bbac..c73ccf8e 100644 --- a/tests/unit/reports/test_types.py +++ b/tests/unit/reports/test_types.py @@ -194,6 +194,9 @@ class TestSessionTotalsArray(object): "meta": {"session_count": 5}, "4": [0, 35, 35, 0, 0, "100", 5, 0, 0, 0, 0, 0, 0], } + encoded_obj_string_no_meta = { + "4": [0, 35, 35, 0, 0, "100", 5, 0, 0, 0, 0, 0, 0], + } def test_decode_session_totals_array_from_legacy(self): expected = SessionTotalsArray( @@ -230,6 +233,16 @@ def test_decode_session_totals_array_string_indexes(self): assert expected.session_count == result.session_count assert expected.non_null_items == result.non_null_items + def test_decode_session_totals_array_string_indexes_no_meta(self): + encoded_obj_copy = deepcopy(self.encoded_obj_string_no_meta) + expected = SessionTotalsArray( + session_count=5, + non_null_items={4: [0, 35, 35, 0, 0, "100", 5, 0, 0, 0, 0, 0, 0]}, + ) + result = SessionTotalsArray.build_from_encoded_data(encoded_obj_copy) + assert expected.session_count == result.session_count + assert expected.non_null_items == result.non_null_items + def test_decode_session_totals_array_no_meta(self): encoded_obj_copy = deepcopy(self.encoded_obj) encoded_obj_copy.pop("meta")