Open leplatrem opened 2 months ago
This appears to be coming from dockerflow's json formatter. I have a unit test going over there that confirms the problem. Will open an issue.
Oh, there is already an issue there. https://github.com/mozilla-services/python-dockerflow/issues/10
Looking at this a bit more, this is more complicated than I'd like. But I think we have a few options:
dateprop.isoformat()
when creating the log recordSafeJSONEncoder
method with something like the options below. But this could be a breaking change for somebody.# option 1, explicit but requires more code
class SafeJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime.datetime):
return o.isoformat()
if isinstance(o, datetime.date):
return o.isoformat()
if isinstance(o, datetime.time):
return o.isoformat()
return repr(o)
# option 2, lazy but would work across multiple object types
class SafeJSONEncoder(json.JSONEncoder):
def default(self, o):
if hasattr(o, 'isoformat') and callable(o.isoformat):
return o.isoformat()
return repr(o)