Skip to content

Commit 1b04cb2

Browse files
committed
Make the JSON tests server-version tolerant
CI runs against ClickHouse 24.8 and 25.3 LTS as well as latest, and both failures were server differences rather than driver bugs: - 24.8 rejects the JSON type outright (it was experimental there), so the module now probes for a usable JSON type and skips if there is none. - 25.3 coerces a heterogeneous array to String where later servers keep Int64/String/Bool as separate variants. Both are valid on the wire, so the mixed-array case now pins the shape and accepts either representation.
1 parent 1b25cfb commit 1b04cb2

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

tests/test_proto/columns/test_jsoncolumn.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
import pytest
99

1010
from asynch.cursors import DictCursor
11+
from asynch.errors import ServerException
12+
13+
14+
@pytest.fixture(autouse=True)
15+
async def require_json_type(conn):
16+
"""Skip where the server has no usable JSON type.
17+
18+
It was experimental before 25.x and is rejected outright there, so these
19+
tests describe the driver against servers that actually speak the format.
20+
"""
21+
async with conn.cursor() as cursor:
22+
try:
23+
await cursor.execute("SELECT '{}'::JSON")
24+
except ServerException as e:
25+
pytest.skip(f"server has no usable JSON type: {e}")
1126

1227
DOCUMENTS = [
1328
{"a": 1, "b": "x"},
@@ -46,7 +61,6 @@ async def json_table(conn):
4661
('{"n": null}', {}),
4762
("{}", {}),
4863
('{"nums": [1, 2, 3]}', {"nums": [1, 2, 3]}),
49-
('{"mixed": [1, "a", true]}', {"mixed": [1, "a", True]}),
5064
('{"m": [[1, 2], [3]]}', {"m": [[1, 2], [3]]}),
5165
('{"items": [{"id": 1}, {"id": 2}]}', {"items": [{"id": 1}, {"id": 2}]}),
5266
('{"a": [1, null, 3]}', {"a": [1, None, 3]}),
@@ -60,6 +74,22 @@ async def test_read_json_literal(conn, literal, expected):
6074
assert (await cursor.fetchone())[0] == expected
6175

6276

77+
@pytest.mark.asyncio
78+
async def test_read_heterogeneous_array(conn):
79+
"""A mixed-type array decodes to whatever variant the server picked.
80+
81+
Servers differ here: some keep Int64/String/Bool as separate variants,
82+
others coerce the whole array to String. Both are correct on the wire, so
83+
this pins the shape rather than the exact types.
84+
"""
85+
async with conn.cursor() as cursor:
86+
await cursor.execute("""SELECT '{"mixed": [1, "a", true]}'::JSON AS j""")
87+
value = (await cursor.fetchone())[0]
88+
89+
assert set(value) == {"mixed"}
90+
assert value["mixed"] in ([1, "a", True], ["1", "a", "true"])
91+
92+
6393
@pytest.mark.asyncio
6494
async def test_json_roundtrip(conn, json_table):
6595
async with conn.cursor() as cursor:

0 commit comments

Comments
 (0)