From: Daniele Varrazzo Date: Sun, 13 Aug 2023 09:48:26 +0000 (+0100) Subject: fix: fix TypeInfo.fetch() with connections using RawCursor as factory X-Git-Tag: pool-3.2.0~66^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d68ae0d78eeb5e8b01ba1fb1d9ca9037520eea42;p=thirdparty%2Fpsycopg.git fix: fix TypeInfo.fetch() with connections using RawCursor as factory --- diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index f33866175..dcbb2c095 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -93,12 +93,13 @@ class TypeInfo: # the function with the connection in the state we found (either idle # or intrans) try: - with conn.transaction(): + from psycopg import Cursor + + with conn.transaction(), Cursor(conn, row_factory=dict_row) as cur: 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() + cur.execute("set local client_encoding to utf8") + cur.execute(cls._get_info_query(conn), {"name": name}) + recs = cur.fetchall() except e.UndefinedObject: return None @@ -109,10 +110,12 @@ class TypeInfo: cls: Type[T], conn: "AsyncConnection[Any]", name: str ) -> Optional[T]: try: + from psycopg import AsyncCursor + 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: + async with AsyncCursor(conn, row_factory=dict_row) as cur: + if conn_encoding(conn) == "ascii": + await cur.execute("set local client_encoding to utf8") await cur.execute(cls._get_info_query(conn), {"name": name}) recs = await cur.fetchall() except e.UndefinedObject: