Skip to content

Commit 780bee9

Browse files
committed
Do not serialize mappings with custom __repr__ as dict-s
Fixes #1296
1 parent f92e970 commit 780bee9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sentry_sdk/serializer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ def _serialize_node_impl(
288288
else safe_repr(obj)
289289
)
290290

291-
elif isinstance(obj, Mapping):
291+
elif isinstance(obj, Mapping) and type(obj).__repr__ in (
292+
object.__repr__, dict.__repr__
293+
):
292294
# Create temporary copy here to avoid calling too much code that
293295
# might mutate our dictionary while we're still iterating over it.
294296
obj = dict(iteritems(obj))

tests/test_serializer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ def test_bytes_serialization_repr(message_normalizer):
6464
def test_serialize_sets(extra_normalizer):
6565
result = extra_normalizer({1, 2, 3})
6666
assert result == [1, 2, 3]
67+
68+
69+
def test_serialize_custom_mapping(extra_normalizer):
70+
class CustomReprDict(dict):
71+
def __repr__(self):
72+
return "custom!"
73+
74+
result = extra_normalizer(CustomReprDict(one=1, two=2))
75+
assert result == "custom!"
76+

0 commit comments

Comments
 (0)