diff --git a/src/sentry/interfaces/exception.py b/src/sentry/interfaces/exception.py index b3e03210adaff2..f9ea76b0aeea16 100644 --- a/src/sentry/interfaces/exception.py +++ b/src/sentry/interfaces/exception.py @@ -63,13 +63,14 @@ def to_python(cls, data, slim_frames=True): type = data.get('type') value = data.get('value') - if not type and ':' in value.split(' ', 1)[0]: - type, value = value.split(':', 1) - # in case of TypeError: foo (no space) - value = value.strip() - - if value is not None and not isinstance(value, six.string_types): + if isinstance(value, six.string_types): + if type is None and ':' in value.split(' ', 1)[0]: + type, value = value.split(':', 1) + # in case of TypeError: foo (no space) + value = value.strip() + elif value is not None: value = json.dumps(value) + value = trim(value, 4096) mechanism = data.get('mechanism') diff --git a/tests/sentry/interfaces/test_exception.py b/tests/sentry/interfaces/test_exception.py index a428f1e190a87f..c77184009aea20 100644 --- a/tests/sentry/interfaces/test_exception.py +++ b/tests/sentry/interfaces/test_exception.py @@ -71,6 +71,14 @@ def test_args_as_old_style(self): assert inst.values[0].value == 'hello world' assert inst.values[0].module == 'foo.bar' + def test_non_string_value_with_no_type(self): + inst = Exception.to_python( + { + 'value': {'foo': 'bar'}, + } + ) + assert inst.values[0].value == '{"foo":"bar"}' + def test_serialize_unserialize_behavior(self): result = type(self.interface).to_python(self.interface.to_json()) assert result.to_json() == self.interface.to_json()