From: Daniele Varrazzo Date: Wed, 1 Feb 2023 00:59:01 +0000 (+0100) Subject: fix: fix TypeInfo.fetch() with a sql_ascii encoding connection X-Git-Tag: pool-3.2.0~127^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca6db5c213ad61af1f4690339248a3a447b31ef5;p=thirdparty%2Fpsycopg.git fix: fix TypeInfo.fetch() with a sql_ascii encoding connection Close #503 --- diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index 519815f01..f33866175 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -15,6 +15,7 @@ from . import sql from . import errors as e from .abc import AdaptContext, Query from .rows import dict_row +from ._encodings import conn_encoding if TYPE_CHECKING: from .connection import BaseConnection, Connection @@ -93,6 +94,8 @@ class TypeInfo: # or intrans) try: with conn.transaction(): + if conn_encoding(conn) == "ascii": + conn.execute("set local client_encoding to utf8") with conn.cursor(row_factory=dict_row) as cur: cur.execute(cls._get_info_query(conn), {"name": name}) recs = cur.fetchall() @@ -107,6 +110,8 @@ class TypeInfo: ) -> Optional[T]: try: async with conn.transaction(): + if conn_encoding(conn) == "ascii": + await conn.execute("set local client_encoding to utf8") async with conn.cursor(row_factory=dict_row) as cur: await cur.execute(cls._get_info_query(conn), {"name": name}) recs = await cur.fetchall()