Skip to content

Commit

Permalink
Do not serialize mappings with custom __repr__ as dict-s
Browse files Browse the repository at this point in the history
Fixes #1296
  • Loading branch information
vmarkovtsev committed Jan 12, 2022
1 parent f92e970 commit 780bee9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sentry_sdk/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ def _serialize_node_impl(
else safe_repr(obj)
)

elif isinstance(obj, Mapping):
elif isinstance(obj, Mapping) and type(obj).__repr__ in (
object.__repr__, dict.__repr__
):
# Create temporary copy here to avoid calling too much code that
# might mutate our dictionary while we're still iterating over it.
obj = dict(iteritems(obj))
Expand Down
10 changes: 10 additions & 0 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ def test_bytes_serialization_repr(message_normalizer):
def test_serialize_sets(extra_normalizer):
result = extra_normalizer({1, 2, 3})
assert result == [1, 2, 3]


def test_serialize_custom_mapping(extra_normalizer):
class CustomReprDict(dict):
def __repr__(self):
return "custom!"

result = extra_normalizer(CustomReprDict(one=1, two=2))
assert result == "custom!"

0 comments on commit 780bee9

Please sign in to comment.