From bfde9f0e3f4f82a202dffa63cc97b5c6c32a5497 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Mon, 16 Jan 2023 21:09:21 +0100 Subject: [PATCH] Fixed TypeInfo for ClientCursor. TypeInfo had a hardcoded binary=True which doesn't work to well for ClientCursor. --- docs/news.rst | 1 + psycopg/psycopg/_typeinfo.py | 4 ++-- tests/test_client_cursor.py | 6 ++++++ tests/test_client_cursor_async.py | 6 ++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index 471d3cd3a..532829270 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -17,6 +17,7 @@ Psycopg 3.1.8 (unreleased) are not found (:ticket:`#473`). - Set `Cursor.rowcount` to the number of rows of each result set from `~Cursor.executemany()` when called with `!returning=True` (:ticket:`#479`). +- Fix `TypeInfo.fetch()` when used with `ClientCursor` (:ticket:`#484`). Current release --------------- diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index 87260d159..519815f01 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -93,7 +93,7 @@ class TypeInfo: # or intrans) try: with conn.transaction(): - with conn.cursor(binary=True, row_factory=dict_row) as cur: + with conn.cursor(row_factory=dict_row) as cur: cur.execute(cls._get_info_query(conn), {"name": name}) recs = cur.fetchall() except e.UndefinedObject: @@ -107,7 +107,7 @@ class TypeInfo: ) -> Optional[T]: try: async with conn.transaction(): - async with conn.cursor(binary=True, row_factory=dict_row) as cur: + async with conn.cursor(row_factory=dict_row) as cur: await cur.execute(cls._get_info_query(conn), {"name": name}) recs = await cur.fetchall() except e.UndefinedObject: diff --git a/tests/test_client_cursor.py b/tests/test_client_cursor.py index e091e9cf1..5ac793b64 100644 --- a/tests/test_client_cursor.py +++ b/tests/test_client_cursor.py @@ -9,6 +9,7 @@ import psycopg from psycopg import sql, rows from psycopg.adapt import PyFormat from psycopg.postgres import types as builtins +from psycopg.types import TypeInfo from .utils import gc_collect, gc_count from .test_cursor import my_row_factory @@ -855,3 +856,8 @@ def test_message_0x33(conn): assert cur.fetchone() == ("test",) assert not notices + + +def test_typeinfo(conn): + info = TypeInfo.fetch(conn, "jsonb") + assert info is not None diff --git a/tests/test_client_cursor_async.py b/tests/test_client_cursor_async.py index 25f4810c0..50f08f7ef 100644 --- a/tests/test_client_cursor_async.py +++ b/tests/test_client_cursor_async.py @@ -6,6 +6,7 @@ from typing import List import psycopg from psycopg import sql, rows from psycopg.adapt import PyFormat +from psycopg.types import TypeInfo from .utils import alist, gc_collect, gc_count from .test_cursor import my_row_factory @@ -727,3 +728,8 @@ async def test_message_0x33(aconn): assert (await cur.fetchone()) == ("test",) assert not notices + + +async def test_typeinfo(aconn): + info = await TypeInfo.fetch(aconn, "jsonb") + assert info is not None -- 2.47.2