Skip to content

Commit

Permalink
Handle string indexes with no meta
Browse files Browse the repository at this point in the history
These changes let `SessionTotalsArray.build_from_encoded_data` handle the creation of `SessionTotalsArray` from encoded data that has no "meta" info and the indexes of the sessions are strings (as it happens when you pull them from storage).

These changes address https://codecov.sentry.io/issues/4326038619/?project=5215654&query=is%3Aunresolved&referrer=issue-stream&stream_index=0
  • Loading branch information
giovanni-guidini committed Jul 19, 2023
1 parent c3d5e38 commit c0852b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shared/reports/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/reports/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c0852b2

Please sign in to comment.