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(
273
273
if result is not NotImplemented :
274
274
return _flatten_annotated (result )
275
275
276
+ sentry_repr = getattr (type (obj ), "__sentry_repr__" , None )
277
+
276
278
if obj is None or isinstance (obj , (bool , number_types )):
277
279
if should_repr_strings or (
278
280
isinstance (obj , float ) and (math .isinf (obj ) or math .isnan (obj ))
@@ -281,8 +283,8 @@ def _serialize_node_impl(
281
283
else :
282
284
return obj
283
285
284
- elif callable (getattr ( obj , " sentry_repr" , None ) ):
285
- return obj . sentry_repr ()
286
+ elif callable (sentry_repr ):
287
+ return sentry_repr (obj )
286
288
287
289
elif isinstance (obj , datetime ):
288
290
return (
Original file line number Diff line number Diff line change 1
1
import sys
2
-
3
2
import pytest
4
3
5
4
from sentry_sdk .serializer import serialize
@@ -68,8 +67,20 @@ def test_serialize_sets(extra_normalizer):
68
67
69
68
def test_serialize_custom_mapping (extra_normalizer ):
70
69
class CustomReprDict (dict ):
71
- def sentry_repr (self ):
70
+ def __sentry_repr__ (self ):
72
71
return "custom!"
73
72
74
73
result = extra_normalizer (CustomReprDict (one = 1 , two = 2 ))
75
74
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