Skip to content
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

Faulty check in indexer_client.asset_balances method makes it impossible to get balances grater than 0. #296

Closed
chrisdewa opened this issue Feb 23, 2022 · 6 comments · Fixed by #508
Assignees
Labels
bug Something isn't working Team Lamprey

Comments

@chrisdewa
Copy link

Subject of the issue

In the V2 Indexer, when trying to retrieve balances, you cannot specify min_balance=0 because of the following check, as 0 is falsely:

        if min_balance:
            query["currency-greater-than"] = min_balance

Your environment

I'm using py-algorand-sdk==1.8.0 but this issue is present in the develop branch of the repository as of 02/23/2022

Steps to reproduce

  1. Set up a v2 indexer client with any node.
  2. retreive balances using client.asset_balances(asset_id, min_balance=0)
  3. the reponse will be equivalent to client.asset_balances(asset_id)

Expected behavior

The function should return accounts with balances greater than 0 (as instructions state)

Actual behavior

The function returns all accounts including those with a balance of 0.

Solution

Instead of

if min_balance:
    query["currency-greater-than"] = min_balance

The code should be:

if min_balance is not None:
    query["currency-greater-than"] = min_balance

Addendum:

This faulty check is actually present in many other places around the sdk including the same function.
I will make a PR if life allows it.
Take care

@chrisdewa chrisdewa added the new-bug Bug report that needs triage label Feb 23, 2022
@chrisdewa
Copy link
Author

I just noticed there's already PR #271 already addresses this issue, but there's some building error. I hope it's not too much trouble to fix

@algochoi
Copy link
Contributor

Thanks for reporting this. I took a look into merging that PR and it looks like the change will not cooperate nicely with our existing tests. We'll have to take a deeper look in to this.

@aorumbayev
Copy link

aorumbayev commented Mar 31, 2022

For anyone wondering if there is a temporary workaround/hotfix that doesn't force you to send direct get request. You can still use the sdk, just call the indexer_request directly.

from algosdk.v2client import indexer

indexer_client = indexer.IndexerClient(
    "",
    "https://algoindexer.algoexplorerapi.io",
    headers={"User-Agent": "algosdk"},
)

response = indexer_client.indexer_request(
    "GET",
    "/assets/{PUT_YOUR_ASA_ID}/balances",
    {"currency-greater-than": 0},
)

@winder
Copy link
Contributor

winder commented Sep 29, 2022

This is related to algorand/algorand-sdk-testing#182

@bigbulb
Copy link

bigbulb commented Apr 27, 2023

Hello. The issue persists in the latest SDK (2.1.2). Is there any timeline for a fix? Thanks in advance.

@tzaffi
Copy link
Contributor

tzaffi commented Apr 27, 2023

Hello. The issue persists in the latest SDK (2.1.2). Is there any timeline for a fix? Thanks in advance.

Thanks @bigbulb for closing duplicate #447. There is no ETA at the moment, but I expect to provide a more direct answer in the first week of May.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Team Lamprey
Projects
None yet
8 participants