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.1.7~11^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2119553d295942612066e48dd726994148c103e7;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 52d5ca7c5..08c5e650c 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -14,6 +14,7 @@ from typing_extensions import TypeAlias 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 @@ -94,6 +95,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() @@ -108,6 +111,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()