]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Fixed TypeInfo for ClientCursor. 484/head
authorFlorian Apolloner <florian@apolloner.eu>
Mon, 16 Jan 2023 20:09:21 +0000 (21:09 +0100)
committerFlorian Apolloner <florian@apolloner.eu>
Mon, 16 Jan 2023 20:35:45 +0000 (21:35 +0100)
TypeInfo had a hardcoded binary=True which doesn't work to well for
ClientCursor.

docs/news.rst
psycopg/psycopg/_typeinfo.py
tests/test_client_cursor.py
tests/test_client_cursor_async.py

index 471d3cd3a7a41e0c51cebc208d30bee5f124ca2f..532829270074c63a7ad561f9e986529a73f3c5ca 100644 (file)
@@ -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
 ---------------
index 87260d159cafd0c77550b7c04d11d18d53001410..519815f01c5a9a2dbe70d7d49d6b6fb765615833 100644 (file)
@@ -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:
index e091e9cf1025f62f2473ae55583b9422000929fd..5ac793b643e16db29791a06dba90081b8d63af5d 100644 (file)
@@ -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
index 25f4810c0fe5f211a5d11d788d2e44e8473c378b..50f08f7ef318d94ec81da81af6e1f8ae51d512fb 100644 (file)
@@ -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