Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aiochclient/_types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ cdef class MapType:
self.value_type = what_py_type(tps[comma_index + 1:], container=True)

cdef dict _convert(self, str string):
key, value = string[1:-1].split(':', 1)
splits = string[1:-1].split(':', 1)
if len(splits) < 2:
return {}
key, value = splits
return {
self.key_type.p_type(key): self.value_type.p_type(value)
}
Expand Down
5 changes: 4 additions & 1 deletion aiochclient/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ def __init__(self, name: str, **kwargs):
self.value_type = what_py_type(tps[comma_index + 1 :], container=True)

def p_type(self, string: str) -> dict:
key, value = string[1:-1].split(':', 1)
splits = string[1:-1].split(':', 1)
if len(splits) < 2:
return {}
key, value = splits
return {
self.key_type.p_type(key): self.value_type.p_type(value)

Expand Down
16 changes: 16 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def rows(uuid):
IPv6Address('2001:44c8:129:2632:33:0:252:2'),
dt.datetime(2018, 9, 21, 10, 32, 23, 999000),
True,
{},
{"hello": "world {' and other things"},
{"hello": {"inner": "world {' and other things"}},
{'key1': {'key2': [uuid]}},
Expand Down Expand Up @@ -127,6 +128,7 @@ def rows(uuid):
None,
dt.datetime(2019, 1, 1, 3, 0),
False,
{},
{"hello": "world {'"},
{"hello": {"inner": "world {'"}},
{'key1': {'key2': [uuid, uuid, uuid]}},
Expand Down Expand Up @@ -221,6 +223,7 @@ async def all_types_db(chclient, rows):
ipv6 Nullable(IPv6),
datetime64 DateTime64(3, 'Europe/Moscow'),
bool Bool,
empty_map Map(String, String),
map Map(String, String),
map_map Map(String, Map(String, String)),
map_map_array_uuid Map(String, Map(String, Array(UUID))),
Expand Down Expand Up @@ -915,6 +918,19 @@ async def test_named_tuples(self):
assert round(result[0]) == 1
assert round(result[1]) == 2

async def test_empty_map(self):
# Test empty map field value
assert await self.select_field("empty_map") == {}
record = await self.select_record("empty_map")
assert record[0] == {}
assert record["empty_map"] == {}

# Test empty map bytes representation
assert await self.select_field_bytes("empty_map") == b"{}"
record = await self.select_record_bytes("empty_map")
assert record[0] == b"{}"
assert record["empty_map"] == b"{}"


@pytest.mark.fetching
@pytest.mark.usefixtures("class_chclient")
Expand Down