From b72b7e77e903735952d996bf8030dcf41ca22541 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 16 Sep 2025 20:30:13 +0200 Subject: [PATCH 1/3] Edge case where passing weird number of params vs normal param types could result in valid data received and decoded, but unable to create the map. --- async_substrate_interface/utils/decoding.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/async_substrate_interface/utils/decoding.py b/async_substrate_interface/utils/decoding.py index 1dc494a..9557159 100644 --- a/async_substrate_interface/utils/decoding.py +++ b/async_substrate_interface/utils/decoding.py @@ -135,11 +135,14 @@ def concat_hash_len(key_hasher: str) -> int: if decode_ss58: if kts[kts.index(", ") + 2 : kts.index(")")] == "scale_info::0": item_key = ss58_encode(bytes(item_key[0]), runtime.ss58_format) - else: - item_key = tuple( - dk[key + 1] for key in range(len(params), len(param_types) + 1, 2) - ) + try: + item_key = tuple( + dk[key + 1] + for key in range(len(params), len(param_types) + 1, 2) + ) + except IndexError: + item_key = dk except Exception as _: if not ignore_decoding_errors: From 0e94d05de2a7d32fd214bc69b75d55f7aeedf8dc Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 16 Sep 2025 20:43:15 +0200 Subject: [PATCH 2/3] Adds tests --- .../test_async_substrate_interface.py | 13 +++++++++++++ tests/integration_tests/test_substrate_interface.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tests/integration_tests/test_async_substrate_interface.py b/tests/integration_tests/test_async_substrate_interface.py index 8f3c3f6..8dab260 100644 --- a/tests/integration_tests/test_async_substrate_interface.py +++ b/tests/integration_tests/test_async_substrate_interface.py @@ -161,3 +161,16 @@ async def test_reconnection(): bh = await substrate.get_chain_finalised_head() assert isinstance(bh, str) assert isinstance(await substrate.get_block_number(bh), int) + + +@pytest.mark.asyncio +async def test_query_map_with_odd_number_of_params(): + async with AsyncSubstrateInterface(ARCHIVE_ENTRYPOINT, ss58_format=42) as substrate: + qm = await substrate.query_map( + "SubtensorModule", + "Alpha", + ["5CoZxgtfhcJKX2HmkwnsN18KbaT9aih9eF3b6qVPTgAUbifj"], + ) + first_record = qm.records[0] + assert len(first_record) == 2 + assert len(first_record[0]) == 4 diff --git a/tests/integration_tests/test_substrate_interface.py b/tests/integration_tests/test_substrate_interface.py index 27e134a..ad80401 100644 --- a/tests/integration_tests/test_substrate_interface.py +++ b/tests/integration_tests/test_substrate_interface.py @@ -100,3 +100,15 @@ def test_query_multiple(): storage_function="OwnedHotkeys", block_hash=block_hash, ) + + +def test_query_map_with_odd_number_of_params(): + with SubstrateInterface(LATENT_LITE_ENTRYPOINT, ss58_format=42) as substrate: + qm = substrate.query_map( + "SubtensorModule", + "Alpha", + ["5CoZxgtfhcJKX2HmkwnsN18KbaT9aih9eF3b6qVPTgAUbifj"], + ) + first_record = qm.records[0] + assert len(first_record) == 2 + assert len(first_record[0]) == 4 From 49488476fb7ab093082c599c31d7fd2dfd49bd4e Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 16 Sep 2025 21:03:28 +0200 Subject: [PATCH 3/3] Changelog + version --- CHANGELOG.md | 5 +++++ pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f685210..f2e8ebf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## 1.5.3 /2025-09-16 +* edge case query map keys by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/186 + +**Full Changelog**: https://github.com/opentensor/async-substrate-interface/compare/v1.5.2...v1.5.3 + ## 1.5.2 /2025-09-08 * Improve test workflows by @basfroman in https://github.com/opentensor/async-substrate-interface/pull/173 * Adds env var support for setting cache size by @thewhaleking in https://github.com/opentensor/async-substrate-interface/pull/174 diff --git a/pyproject.toml b/pyproject.toml index 08f8ca0..1d41c93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "async-substrate-interface" -version = "1.5.2" +version = "1.5.3" description = "Asyncio library for interacting with substrate. Mostly API-compatible with py-substrate-interface" readme = "README.md" license = { file = "LICENSE" }