From 87f6db8fa46b51702a18aef6347e6c0c53adf9e4 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 4 Sep 2025 11:43:03 +0200 Subject: [PATCH] test: add test to reproduce set_types being ignored It has been reported ignored in the C implementation in binary format. See #1153 --- tests/test_copy.py | 9 +++++++++ tests/test_copy_async.py | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/test_copy.py b/tests/test_copy.py index 9b5604a9c..185eb72ff 100644 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -116,6 +116,15 @@ def test_rows(conn, format): assert conn.info.transaction_status == pq.TransactionStatus.INTRANS +@pytest.mark.parametrize("format", pq.Format) +def test_set_types(conn, format): + cur = conn.cursor() + ensure_table(cur, "id serial primary key, data jsonb") + with cur.copy(f"copy copy_in (data) from stdin (format {format.name})") as copy: + copy.set_types(["jsonb"]) + copy.write_row([{"foo": "bar"}]) + + def test_set_custom_type(conn, hstore): command = """copy (select '"a"=>"1", "b"=>"2"'::hstore) to stdout""" cur = conn.cursor() diff --git a/tests/test_copy_async.py b/tests/test_copy_async.py index ae1fce2ad..a4cc4d744 100644 --- a/tests/test_copy_async.py +++ b/tests/test_copy_async.py @@ -120,6 +120,17 @@ async def test_rows(aconn, format): assert aconn.info.transaction_status == pq.TransactionStatus.INTRANS +@pytest.mark.parametrize("format", pq.Format) +async def test_set_types(aconn, format): + cur = aconn.cursor() + await ensure_table_async(cur, "id serial primary key, data jsonb") + async with cur.copy( + f"copy copy_in (data) from stdin (format {format.name})" + ) as copy: + copy.set_types(["jsonb"]) + await copy.write_row([{"foo": "bar"}]) + + async def test_set_custom_type(aconn, hstore): command = """copy (select '"a"=>"1", "b"=>"2"'::hstore) to stdout""" cur = aconn.cursor() -- 2.47.3