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/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: 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" } 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