if isinstance(ad, tuple):
if oid == 0:
oid = ad[1]
+ got_type = type(item)
+ elif oid != ad[1]:
+ raise e.DataError(
+ f"array contains different types,"
+ f" at least {got_type} and {type(item)}"
+ )
ad = ad[0]
tokens.append(escape_item(ad))
if isinstance(ad, tuple):
if head[2] == 0:
head[2] = ad[1]
+ got_type = type(item)
+ elif head[2] != ad[1]:
+ raise e.DataError(
+ f"array contains different types,"
+ f" at least {got_type} and {type(item)}"
+ )
ad = ad[0]
if ad is None:
head[1] = 1
import pytest
+import psycopg3
from psycopg3.types import builtins
-from psycopg3.adapt import TypeCaster, UnknownCaster, Format
+from psycopg3.adapt import TypeCaster, UnknownCaster, Format, Transformer
from psycopg3.types.array import UnknownArrayCaster, ArrayCaster
assert cur.fetchone()[0]
+@pytest.mark.parametrize(
+ "input",
+ [[["a"], ["b", "c"]], [["a"], []], [[]], [[["a"]], ["b"]], [True, b"a"]],
+)
+def test_bad_binary_array(input):
+ tx = Transformer()
+ with pytest.raises(psycopg3.DataError):
+ tx.adapt(input, Format.BINARY)
+
+
@pytest.mark.parametrize("fmt_out", [Format.TEXT, Format.BINARY])
@pytest.mark.parametrize("want, obj", tests_int)
def test_cast_list_int(conn, obj, want, fmt_out):