From fdcee6b613a1f52f6d22bce58c290fe7d1ddc2d2 Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Mon, 18 Mar 2019 13:46:10 +0000 Subject: [PATCH] Fix #1349 Skipkeys when serializing to json Also, don't try to call json.dumps with "encoding" keyword in Python3, which does not support it. --- raven/utils/json.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/raven/utils/json.py b/raven/utils/json.py index ef8fe25d1..5c6860398 100644 --- a/raven/utils/json.py +++ b/raven/utils/json.py @@ -15,6 +15,7 @@ import json from .basic import is_namedtuple +from .compat import PY2 try: @@ -56,11 +57,16 @@ def better_decoder(data): def dumps(value, **kwargs): + kwargs['skipkeys'] = True try: return json.dumps(value, cls=BetterJSONEncoder, **kwargs) except Exception: - kwargs['encoding'] = 'safe-utf-8' - return json.dumps(value, cls=BetterJSONEncoder, **kwargs) + if PY2: + # 'encoding' is only available in Py2 + kwargs['encoding'] = 'safe-utf-8' + return json.dumps(value, cls=BetterJSONEncoder, **kwargs) + else: + raise def loads(value, **kwargs):