-
Notifications
You must be signed in to change notification settings - Fork 20
Fix: error 500 on get_credit_balances_handler #972
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
Conversation
23e83c7 to
3f8bfb2
Compare
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.
Pull request overview
Fixes the /api/v0/credit_balances 500 by adjusting how DB credit balance rows are converted into API response models, and by tightening the DB accessor function signatures.
Changes:
- Build
AddressCreditBalanceResponsefrom(address, balance)tuple values instead of callingmodel_validateon DB rows. - Update
count_credit_balancesinvocation to pass onlymin_balance. - Tighten DB accessor type hints/signatures for
get_credit_balancesandcount_credit_balances.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/aleph/web/controllers/accounts.py |
Fixes response formatting for credit balances and updates total-count call signature. |
src/aleph/db/accessors/balances.py |
Tightens credit balance accessor/count signatures and adds explicit return typing. |
Comments suppressed due to low confidence (1)
src/aleph/db/accessors/balances.py:394
count_credit_balancessignature was tightened (removed**kwargs), so incorrect callers will now fail fast. Add focused tests aroundmin_balancefiltering/counting so the handler'spagination_totalbehavior is locked in and stays consistent withget_credit_balances.
def count_credit_balances(session: DbSession, min_balance: int = 0) -> int:
"""
Count addresses with credit balances.
Uses the cached balances from the credit_balances table.
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| credit_balances = get_credit_balances(session, **find_filters) | ||
|
|
||
| formatted_credit_balances = [ | ||
| AddressCreditBalanceResponse.model_validate(b) for b in credit_balances | ||
| AddressCreditBalanceResponse(address=b[0], credits=b[1]) | ||
| for b in credit_balances | ||
| ] | ||
|
|
||
| total_credit_balances = count_credit_balances(session, **find_filters) | ||
| total_credit_balances = count_credit_balances( | ||
| session, find_filters.get("min_balance", 0) | ||
| ) |
Copilot
AI
Jan 22, 2026
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.
This change fixes a production 500 by altering how the endpoint formats DB rows and how the total is computed. There are controller tests in tests/web/controllers/test_accounts_controllers.py, but none covering /credit_balances; please add a regression test for get_credit_balances_handler that exercises the response formatting and min_balance filtering/counting to prevent this from reoccurring.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Self proofreading checklist
Changes
This pull request makes a small change to how credit balances are formatted in the
get_credit_balances_handlerfunction. Instead of using themodel_validatemethod, it now explicitly createsAddressCreditBalanceResponseobjects using the address and credits values from each balance.How to test
http://46.255.204.204:4024/api/v0/credit_balances # WORKING
https://api2.aleph.im/api/v0/credit_balances # ERROR 500