Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sentry_sdk/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math
import sys
from collections.abc import Mapping, Sequence, Set
from array import array
from collections.abc import Mapping
from datetime import datetime
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -53,7 +54,7 @@ def add_global_repr_processor(processor: "ReprProcessor") -> None:
global_repr_processors.append(processor)


sequence_types: "List[type]" = [Sequence, Set]
sequence_types: "List[type]" = [tuple, list, set, frozenset, array]


def add_repr_sequence_type(ty: type) -> None:
Expand Down
39 changes: 39 additions & 0 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from array import array

import pytest

Expand Down Expand Up @@ -180,3 +181,41 @@ def test_max_value_length(body_normalizer):
result = body_normalizer(data, max_value_length=max_value_length)

assert len(result["key"]) == max_value_length


def test_serialize_local_vars():
# This was added to make sure we don't try to iterate over instances of
# custom classes with an __iter__ method due to potential side effects
class Custom:
def __init__(self, items):
self.items = items

def __len__(self):
return self.items.__len__()

def __getitem__(self, item):
return self.items.__getitem__(item)

def __iter__(self):
raise ValueError

local_vars = {
"str": "123",
"bytes": b"123",
"list": [1, 2, 3],
"set": {1, 2, 3},
"frozenset": frozenset([1, 2, 3]),
"array": array("l", [1, 2, 3]),
"custom": Custom([1, 2, 3]),
}

result = serialize(local_vars, is_vars=True)
assert result["str"] == "'123'"
assert result["bytes"] == "b'123'"
assert result["list"] == ["1", "2", "3"]
assert sorted(result["set"]) == ["1", "2", "3"]
assert sorted(result["frozenset"]) == ["1", "2", "3"]
assert result["array"] == ["1", "2", "3"]
assert result["custom"].startswith(
"<tests.test_serializer.test_serialize_local_vars.<locals>.Custom object at"
)
Loading