Skip to content

Conversation

@1yam
Copy link
Member

@1yam 1yam commented Jan 21, 2026

Self proofreading checklist

  • Is my code clear enough and well documented
  • Are my files well typed
  • New translations have been added or updated if new strings have been introduced in the frontend
  • Database migrations file are included
  • Are there enough tests
  • Documentation has been included (for new feature)

Changes

This pull request makes a small change to how credit balances are formatted in the get_credit_balances_handler function. Instead of using the model_validate method, it now explicitly creates AddressCreditBalanceResponse objects 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

@1yam 1yam requested review from Copilot and odesenfans and removed request for Copilot January 21, 2026 17:45
@1yam 1yam self-assigned this Jan 21, 2026
Copilot AI review requested due to automatic review settings January 22, 2026 11:52
@1yam 1yam force-pushed the 1yam-fix-get-credit-balances-handler branch from 23e83c7 to 3f8bfb2 Compare January 22, 2026 11:53
Copy link

Copilot AI left a 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 AddressCreditBalanceResponse from (address, balance) tuple values instead of calling model_validate on DB rows.
  • Update count_credit_balances invocation to pass only min_balance.
  • Tighten DB accessor type hints/signatures for get_credit_balances and count_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_balances signature was tightened (removed **kwargs), so incorrect callers will now fail fast. Add focused tests around min_balance filtering/counting so the handler's pagination_total behavior is locked in and stays consistent with get_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.

Comment on lines 221 to 230
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)
)
Copy link

Copilot AI Jan 22, 2026

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@odesenfans odesenfans merged commit 853135a into main Jan 22, 2026
4 of 5 checks passed
@odesenfans odesenfans deleted the 1yam-fix-get-credit-balances-handler branch January 22, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants