Skip to content

Commit fdcee6b

Browse files
committed
Fix getsentry#1349 Skipkeys when serializing to json
Also, don't try to call json.dumps with "encoding" keyword in Python3, which does not support it.
1 parent d891c20 commit fdcee6b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

raven/utils/json.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616

1717
from .basic import is_namedtuple
18+
from .compat import PY2
1819

1920

2021
try:
@@ -56,11 +57,16 @@ def better_decoder(data):
5657

5758

5859
def dumps(value, **kwargs):
60+
kwargs['skipkeys'] = True
5961
try:
6062
return json.dumps(value, cls=BetterJSONEncoder, **kwargs)
6163
except Exception:
62-
kwargs['encoding'] = 'safe-utf-8'
63-
return json.dumps(value, cls=BetterJSONEncoder, **kwargs)
64+
if PY2:
65+
# 'encoding' is only available in Py2
66+
kwargs['encoding'] = 'safe-utf-8'
67+
return json.dumps(value, cls=BetterJSONEncoder, **kwargs)
68+
else:
69+
raise
6470

6571

6672
def loads(value, **kwargs):

0 commit comments

Comments
 (0)