Commit a59709c3 authored by Jérome Perrin's avatar Jérome Perrin

LongRequestLogger_dumper: tolerates bytes or str when dumping query

DB.query accepts either bytes or str on python3. We need to decode the
query here to display it in traceback and we must not fail when we
have bytes with non UTF-8 characters, which can happen with binary
columns
parent fd2bccad
...@@ -13,6 +13,7 @@ import sys ...@@ -13,6 +13,7 @@ import sys
import time import time
import traceback import traceback
import six
from six.moves import StringIO from six.moves import StringIO
from six.moves._thread import get_ident from six.moves._thread import get_ident
from Products.ERP5Type.Utils import bytes2str from Products.ERP5Type.Utils import bytes2str
...@@ -61,7 +62,12 @@ class Dumper(object): ...@@ -61,7 +62,12 @@ class Dumper(object):
def _extract_sql(self, frame, func_code=DB._query.__code__): def _extract_sql(self, frame, func_code=DB._query.__code__):
while frame is not None: while frame is not None:
if frame.f_code is func_code: if frame.f_code is func_code:
return bytes2str(frame.f_locals['query']) query = frame.f_locals['query']
if six.PY3 and isinstance(query, bytes):
return query.decode(
'utf-8',
errors='backslashreplace')
return query
frame = frame.f_back frame = frame.f_back
del DB del DB
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment