Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SimpleLazyObject in payloads #297

Merged
merged 3 commits into from
Dec 18, 2018
Merged
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
5 changes: 3 additions & 2 deletions rollbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import requests
import six

from rollbar.lib import events, filters, dict_merge, parse_qs, text, transport, urljoin, iteritems
from rollbar.lib import events, filters, dict_merge, parse_qs, text, transport, urljoin, iteritems, defaultJSONEncode


__version__ = '0.14.5'
__log_name__ = 'rollbar'
Expand Down Expand Up @@ -1328,7 +1329,7 @@ def _build_payload(data):


def _serialize_payload(payload):
return json.dumps(payload)
return json.dumps(payload, default=defaultJSONEncode)


def _send_payload(payload_str, access_token):
Expand Down
14 changes: 14 additions & 0 deletions rollbar/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
from array import array
import json

try:
# Python 3
Expand Down Expand Up @@ -212,3 +213,16 @@ def unencodable_object_label(data):
def undecodable_object_label(data):
return '<Undecodable type:(%s) base64:(%s)>' % (type(data).__name__,
base64.b64encode(data).decode('ascii'))

try:
from django.utils.functional import SimpleLazyObject
except ImportError:
SimpleLazyObject = None


def defaultJSONEncode(o):
if SimpleLazyObject and isinstance(o, SimpleLazyObject):
if not o._wrapped:
o._setup()
return o._wrapped
return repr(o) + " is not JSON serializable"