]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: add test to reproduce set_types being ignored
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 4 Sep 2025 09:43:03 +0000 (11:43 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 13 Oct 2025 12:52:51 +0000 (14:52 +0200)
It has been reported ignored in the C implementation in binary format. See #1153

tests/test_copy.py
tests/test_copy_async.py

index 9b5604a9cea8994c87be1db4478f6a45b33294c9..185eb72ff6530bc376bff9b486b8ab747403e93c 100644 (file)
@@ -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()
index ae1fce2add05391f4b06a593cbe9a7684eac2084..a4cc4d744e20ada51e20139b1c8903afdb87f2ce 100644 (file)
@@ -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()