From 99e3934ff4c05b56457fe2bfd4abc143329d0b75 Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Tue, 24 Nov 2026 08:08:37 +0100 Subject: [PATCH] Support nested Prism document parameters --- polypheny/serialize.py | 7 +++++++ tests/test_serialize.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/polypheny/serialize.py b/polypheny/serialize.py index 8e147fb..1915a0b 100644 --- a/polypheny/serialize.py +++ b/polypheny/serialize.py @@ -70,8 +70,15 @@ def _py2proto(value, v): elif value is None: v.null.CopyFrom(value_pb2.ProtoNull()) elif type(value) is list: + v.list.SetInParent() for element in value: v.list.values.append(py2proto(element)) + elif type(value) is dict: + v.document.SetInParent() + for key, element in value.items(): + if not isinstance(key, str): + raise NotSupportedError("Document keys must be strings") + py2proto(element, v.document.entries[key]) else: raise NotSupportedError() diff --git a/tests/test_serialize.py b/tests/test_serialize.py index ea8d35c..8b3b076 100644 --- a/tests/test_serialize.py +++ b/tests/test_serialize.py @@ -225,11 +225,15 @@ def test_serialize_varbinary(cur): assert cur.fetchone()[0] == b'Hello World' assert cur.fetchone() is None -def test_serialize_not_implemented(cur): - cur.execute('DROP TABLE IF EXISTS t') - cur.execute('CREATE TABLE t(i INTEGER NOT NULL, a INTEGER, PRIMARY KEY(i))') +@pytest.mark.parametrize('value', [[], {}, {'a': [None, {}, []], 'b': {'active': True}}]) +def test_serialize_containers_local(value): + assert polypheny.serialize.proto2py(polypheny.serialize.py2proto(value)) == value + + +@pytest.mark.parametrize('value', [object(), {1: 'not a string key'}]) +def test_serialize_not_implemented(value): with pytest.raises(polypheny.NotSupportedError): - cur.execute('INSERT INTO t(i, a) VALUES (0, ?)', ({'a': 'b'},)) + polypheny.serialize.py2proto(value) def test_trailing_semicolon(cur): cur.execute("SELECT 1;")