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

serializer: transform: improve exception msg and fallback #1294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions raven/utils/serializer/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def transform(self, value, **kwargs):
try:
return repr(value)
except Exception as e:
logger.exception(e)
logger.exception('Failed to serialize obj (%s): %s', objid, e)
# It's common case that a model's __unicode__ definition
# may try to query the database which if it was not
# cleaned up correctly, would hit a transaction aborted
# exception
return text_type(type(value))
# exception.
return '%s (%s)' % (text_type(type(value)), objid)
finally:
self.context.remove(objid)

Expand Down
9 changes: 6 additions & 3 deletions tests/utils/encoding/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,19 @@ def __sentry__(self):
expected = "u'example'"
self.assertEqual(result, expected)

def test_broken_repr(self):
def test_broken_repr(self, caplog):
class Foo(object):
def __repr__(self):
raise ValueError

result = transform(Foo())
expected = "<class 'tests.utils.encoding.tests.Foo'>"
obj = Foo()
result = transform(obj)
import sys
if sys.version_info[0] == 3 and sys.version_info[1] >= 3:
expected = "<class 'tests.utils.encoding.tests.TransformTest.test_broken_repr.<locals>.Foo'>"
else:
expected = "<class 'tests.utils.encoding.tests.Foo'>"
expected += ' (%s)' % (id(obj),)
assert result == expected

def test_recursion_max_depth(self):
Expand Down