Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit b5049a9

Browse files
committed
serializer: transform: improve exception msg and fallback
1 parent ea000f5 commit b5049a9

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

raven/utils/serializer/manager.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def transform(self, value, **kwargs):
7575
try:
7676
return repr(value)
7777
except Exception as e:
78-
logger.exception(e)
78+
logger.exception('Failed to serialize obj (%s): %s', objid, e)
7979
# It's common case that a model's __unicode__ definition
8080
# may try to query the database which if it was not
8181
# cleaned up correctly, would hit a transaction aborted
82-
# exception
83-
return text_type(type(value))
82+
# exception.
83+
return '%s (%s)' % (text_type(type(value)), objid)
8484
finally:
8585
self.context.remove(objid)
8686

tests/utils/encoding/tests.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,19 @@ def __sentry__(self):
152152
expected = "u'example'"
153153
self.assertEqual(result, expected)
154154

155-
def test_broken_repr(self):
155+
def test_broken_repr(self, caplog):
156156
class Foo(object):
157157
def __repr__(self):
158158
raise ValueError
159159

160-
result = transform(Foo())
161-
expected = "<class 'tests.utils.encoding.tests.Foo'>"
160+
obj = Foo()
161+
result = transform(obj)
162162
import sys
163163
if sys.version_info[0] == 3 and sys.version_info[1] >= 3:
164164
expected = "<class 'tests.utils.encoding.tests.TransformTest.test_broken_repr.<locals>.Foo'>"
165+
else:
166+
expected = "<class 'tests.utils.encoding.tests.Foo'>"
167+
expected += ' (%s)' % (id(obj),)
165168
assert result == expected
166169

167170
def test_recursion_max_depth(self):

0 commit comments

Comments
 (0)