Psycopg 3.2.11 (unreleased)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Fix bad data on error in binary copy (:ticket:`#1147`).
- Don't raise warning, and don't leak resources, if a builtin function is used
as JSON dumper/loader function (:ticket:`#1165`).
else:
pos = PyByteArray_GET_SIZE(out)
- # let's start from a nice chunk
- # (larger than most fixed size; for variable ones, oh well, we'll resize it)
- cdef char *target = CDumper.ensure_size(
- out, pos, sizeof(berowlen) + 20 * rowlen)
+ cdef char *target = CDumper.ensure_size(out, pos, sizeof(berowlen))
# Write the number of fields as network-order 16 bits
memcpy(target, <void *>&berowlen, sizeof(berowlen))
assert cur.description[2].name == "column_3"
+def test_binary_partial_row(conn):
+ cur = conn.cursor()
+ ensure_table(cur, "id serial primary key, num int4, arr int4[][]")
+ with pytest.raises(
+ psycopg.DataError, match="nested lists have inconsistent depths"
+ ):
+ with cur.copy("copy copy_in (num, arr) from stdin (format binary)") as copy:
+ copy.set_types(["int4", "int4[]"])
+ copy.write_row([15, None])
+ copy.write_row([16, [[None], None]])
+
+
@pytest.mark.parametrize(
"format, buffer",
[(pq.Format.TEXT, "sample_text"), (pq.Format.BINARY, "sample_binary")],
assert cur.description[2].name == "column_3"
+async def test_binary_partial_row(aconn):
+ cur = aconn.cursor()
+ await ensure_table_async(cur, "id serial primary key, num int4, arr int4[][]")
+ with pytest.raises(
+ psycopg.DataError, match="nested lists have inconsistent depths"
+ ):
+ async with cur.copy(
+ "copy copy_in (num, arr) from stdin (format binary)"
+ ) as copy:
+ copy.set_types(["int4", "int4[]"])
+ await copy.write_row([15, None])
+ await copy.write_row([16, [[None], None]])
+
+
@pytest.mark.parametrize(
"format, buffer",
[(pq.Format.TEXT, "sample_text"), (pq.Format.BINARY, "sample_binary")],