File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -273,6 +273,8 @@ def _serialize_node_impl(
273273 if result is not NotImplemented :
274274 return _flatten_annotated (result )
275275
276+ sentry_repr = getattr (type (obj ), "__sentry_repr__" , None )
277+
276278 if obj is None or isinstance (obj , (bool , number_types )):
277279 if should_repr_strings or (
278280 isinstance (obj , float ) and (math .isinf (obj ) or math .isnan (obj ))
@@ -281,8 +283,8 @@ def _serialize_node_impl(
281283 else :
282284 return obj
283285
284- elif callable (getattr ( obj , " sentry_repr" , None ) ):
285- return obj . sentry_repr ()
286+ elif callable (sentry_repr ):
287+ return sentry_repr (obj )
286288
287289 elif isinstance (obj , datetime ):
288290 return (
Original file line number Diff line number Diff line change 11import sys
2-
32import pytest
43
54from sentry_sdk .serializer import serialize
@@ -68,8 +67,20 @@ def test_serialize_sets(extra_normalizer):
6867
6968def test_serialize_custom_mapping (extra_normalizer ):
7069 class CustomReprDict (dict ):
71- def sentry_repr (self ):
70+ def __sentry_repr__ (self ):
7271 return "custom!"
7372
7473 result = extra_normalizer (CustomReprDict (one = 1 , two = 2 ))
7574 assert result == "custom!"
75+
76+
77+ def test_custom_mapping_doesnt_mess_with_mock (extra_normalizer ):
78+ """
79+ Adding the __sentry_repr__ magic method check in the serializer
80+ shouldn't mess with how mock works. This broke some stuff when we added
81+ sentry_repr without the dunders.
82+ """
83+ mock = pytest .importorskip ("unittest.mock" )
84+ m = mock .Mock ()
85+ extra_normalizer (m )
86+ assert len (m .mock_calls ) == 0
You can’t perform that action at this time.
0 commit comments