#8 fixes the exception that can happen when you log objects. What'd be even nicer, as @jezdez pointed out, would be to handle datetimes/dates : currently they are serialized as "datetime.datetime(2017, 4, 6, 9, 27, 7, 479427)" because that's the repr() for a datetime object, but we could do better by using DjangoJSONEncoder, which knows how to handle those objects and more.
Something like this should work, to test:
class SafeJSONEncoder(json.JSONEncoder):
def default(self, o):
return repr(o)
class SafeDjangoJSONEncoder(DjangoJSONEncoder, SafeJSONEncoder):
pass
Then use cls=SafeDjangoJSONEncoder when doing the json.dumps.
#8 fixes the exception that can happen when you log objects. What'd be even nicer, as @jezdez pointed out, would be to handle datetimes/dates : currently they are serialized as
"datetime.datetime(2017, 4, 6, 9, 27, 7, 479427)"because that's therepr()for adatetimeobject, but we could do better by usingDjangoJSONEncoder, which knows how to handle those objects and more.Something like this should work, to test:
Then use
cls=SafeDjangoJSONEncoderwhen doing thejson.dumps.