From 6e558c854f18f487e57992e64b58ad9f4a0031b2 Mon Sep 17 00:00:00 2001 From: Ivo De Decker Date: Tue, 7 Apr 2020 13:42:09 +0000 Subject: [PATCH] daklib/dbconn.py: set database connection to utf-8 for python3 --- daklib/dbconn.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index e6c47867..32d79b40 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2537,8 +2537,14 @@ class DBConn(object): engine_args['pool_size'] = int(cnf['DB::PoolSize']) if 'DB::MaxOverflow' in cnf: engine_args['max_overflow'] = int(cnf['DB::MaxOverflow']) - if cnf.get('DB::Unicode') == 'false': - engine_args['use_native_unicode'] = False + if six.PY2: + # in python2, we want to get str() from the database + # if we use the native unicode, we get unicode() + if cnf.get('DB::Unicode') == 'false': + engine_args['use_native_unicode'] = False + else: + # in python3, we don't support non-utf-8 connections + engine_args['client_encoding'] = 'utf-8' # Monkey patch a new dialect in in order to support service= syntax import sqlalchemy.dialects.postgresql -- GitLab