[FIX] Log failed queries decoded

Starting with Python 3, queries sent by psyocopg2 are stored as `bytes()` objects.

Logging those raw makes them appear unformatted, harder to read than in v10 or lower Odoo versions (i.e. `\n` instead of a raw newline character).

Decoding the query into unicode makes it easier to read in the logs.

closes odoo/odoo#38074

X-original-commit: 329accde2ed6d4dbfdde6d3d99d71e21d15396b7
Signed-off-by: Christophe Simonis <chs@odoo.com>
This commit is contained in:
Jairo Llopis
2019-10-08 14:12:23 +00:00
committed by Christophe Simonis
parent bb5ceeaa1b
commit 8ad360ccd3
+1 -1
View File
@@ -240,7 +240,7 @@ class Cursor(object):
res = self._obj.execute(query, params)
except Exception as e:
if self._default_log_exceptions if log_exceptions is None else log_exceptions:
_logger.error("bad query: %s\nERROR: %s", self._obj.query.decode() or query, e)
_logger.error("bad query: %s\nERROR: %s", tools.ustr(self._obj.query or query), e)
raise
# simple query count is always computed