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

Commit

Permalink
fix: Dont serialize nan when present in frame local vars (#1312)
Browse files Browse the repository at this point in the history
* fix: Dont serialize nan when present in vars

* fix: Simplify float serializer

* fix: Tests

* fix: Convert all numbers to string
  • Loading branch information
untitaker authored Dec 19, 2018
1 parent d9e787b commit 5cff205
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
9 changes: 5 additions & 4 deletions raven/utils/serializer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,22 @@ class BooleanSerializer(Serializer):
types = (bool,)

def serialize(self, value, **kwargs):
return bool(value)
return repr(bool(value))


class FloatSerializer(Serializer):
types = (float,)

def serialize(self, value, **kwargs):
return float(value)
# Wrap with repr to convert inf/nan to string
return repr(float(value))


class IntegerSerializer(Serializer):
types = (int,)

def serialize(self, value, **kwargs):
return int(value)
return repr(int(value))


class FunctionSerializer(Serializer):
Expand All @@ -197,7 +198,7 @@ class LongSerializer(Serializer):
types = (long,) # noqa

def serialize(self, value, **kwargs):
return long(value) # noqa
return repr(long(value)) # noqa


# register all serializers, order matters
Expand Down
12 changes: 12 additions & 0 deletions tests/base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ def test_exception_event(self):
self.assertEquals(frame['function'], 'test_exception_event')
self.assertTrue('timestamp' in event)

def test_exception_nan_in_vars(self):
try:
foo = float("nan") # noqa
raise ValueError("foo")
except ValueError:
self.client.captureException()

event, = self.client.events
exc, = event['exception']['values']
frame, = exc['stacktrace']['frames']
assert frame['vars']['foo'] == "nan"

def test_exception_event_true_exc_info(self):
try:
raise ValueError('foo')
Expand Down
11 changes: 4 additions & 7 deletions tests/utils/encoding/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,18 @@ def test_bad_string(self):

def test_float(self):
result = transform(13.0)
self.assertEqual(type(result), float)
self.assertEqual(result, 13.0)
self.assertEqual(result, "13.0")

def test_bool(self):
result = transform(True)
self.assertEqual(type(result), bool)
self.assertEqual(result, True)
self.assertEqual(result, 'True')

def test_int_subclass(self):
class X(int):
pass

result = transform(X())
self.assertEqual(type(result), int)
self.assertEqual(result, 0)
self.assertEqual(result, '0')

def test_dict_keys(self):
x = {'foo': 'bar'}
Expand Down Expand Up @@ -176,7 +173,7 @@ def test_recursion_max_depth(self):
def test_list_max_length(self):
x = list(range(10))
result = transform(x, list_max_length=3)
self.assertEqual(result, (0, 1, 2))
self.assertEqual(result, ('0', '1', '2'))

def test_dict_max_length(self):
x = dict((x, x) for x in range(10))
Expand Down

0 comments on commit 5cff205

Please sign in to comment.