When a dictionary is passed as a message to logger.exception, it can be modified unexpectedly, and this can cause issues if the dict is reused. For instance, this code will result in exc_info being added to the flask JSON response when an error occurs.
When a dictionary is passed as a message to
logger.exception
, it can be modified unexpectedly, and this can cause issues if the dict is reused. For instance, this code will result inexc_info
being added to the flask JSON response when an error occurs.Upon finding the cause, the fix was pretty clear and we defined the dict inline in both call sites:
That said, this isn't something I would expect the library to do, and it took a bit of time to trace this to the library's
format
method. It seems to me that this could be fixed by modifying line 188 https://github.com/madzak/python-json-logger/blob/e2287881d01e276744dfd85d74944c72954d38aa/src/pythonjsonlogger/jsonlogger.py#L188 fromto
But I am not aware of all of the use cases so I can't be sure if this would be the correct approach.