]> 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>
Tue, 14 Oct 2025 00:13:28 +0000 (02:13 +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 c4e4ebc0b1531b51f9165e70500dbc3263acc209..95fc72db1e4667e5a2eedc5e6f0a6e20c11b44e7 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 a23802ca0f70c3858fe4d2e1f827064744dd5121..9f5363b9988e8528172256fb3582d7465ef0a842 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()