-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed a bug in the get_subnets function #2240
base: staging
Are you sure you want to change the base?
Fixed a bug in the get_subnets function #2240
Conversation
Fixed a bug in the get_subnets function where list comprehension caused truncation of results. Replaced it with a manual iteration to ensure all subnets are retrieved.
tests/unit_tests/test_subtensor.py
Outdated
"""Test get_subnets returns a list of the correct length.""" | ||
# Prep | ||
block = 123 | ||
num_records = 50 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this test for length > 100?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right—I missed a zero. I've added it and pushed a changed version along with the updated test, but the test still doesn't catch the issue. I also updated get_subnets again and verified it by running your snippet.
import bittensor
sub = bittensor.subtensor("wss://test.chain.opentensor.ai:443")
subnets = sub.get_subnets()
n_subnets = sub.get_total_subnets()
len(subnets) == n_subnets
# True; Expected: True
Thanks for the contribution! See example: import bittensor
subtensor = bittensor.subtensor(network="wss://test.chain.opentensor.ai:443")
s = subtensor.get_subnets()
len(s)
# 100; Expected > 100 I would consider using the paging functionality of pysub-interface |
…com/niljub/bittensor into hotfix/7.3.0/get-subnets-fix/niljub
"Fixed a bug in the get_subnets function where pagination led to truncated results. The function now iterates through the entire result set, loading all items into memory without pagination issues.
a9cb336
to
ad1c35a
Compare
I initially tested the fix using your snippet from the bug report issue. However, during the cleanup process, I introduced an issue that wasn't caught even with 500 networks. I've now pushed a working version and thoroughly tested it with the snippet, though the solution is a bit more barebones.
I can certainly rewrite the function to use pysub-interface. However, this would also require modifying the query_map_subtensor function and incorporating a start_key. This way, we can leverage the substrate to retrieve results page by page as QueryMapResults. If this approach is preferred, let me know and I will implement it. |
Hi. Taking a look at this today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Child Hotkeys netuid Refactor
…-and-assertions Applies metagraph fix and assertions
…tensor-reconnection-logic Add reconnection logic + tests
…pentensor#2287) * removed exit sys call for ConnectionRefusedError in _get_substrate * removed unnecessary sys import * ruff format fix
f13f5f3
to
73d9fd4
Compare
Bug
The get_subnets function was truncating to max. 100 results due to list comprehensions handling of iterators. The bug has been described in #2208.
Description of the Change
Replaced list comprehension with a manual iteration to ensure all subnet UIDs are retrieved, addressing the issue of truncated results.
Alternate Designs
Considered increasing fetch limits but chose manual iteration for more reliable results.
Possible Drawbacks
No significant drawbacks, just a minor increase in code complexity.
Verification Process
Added a test to check the length of the result list, ensuring all records are processed correctly. Ran all existing tests to confirm no regressions.
Release Notes
Fixed an issue in get_subnets where the result list was being truncated, ensuring complete retrieval of subnets.