Skip to content

fix: handle None distribution data in portfolio dashboard#26

Open
themavik wants to merge 1 commit intohummingbot:mainfrom
themavik:fix-portfolio-none-distribution
Open

fix: handle None distribution data in portfolio dashboard#26
themavik wants to merge 1 commit intohummingbot:mainfrom
themavik:fix-portfolio-none-distribution

Conversation

@themavik
Copy link

Summary

When asyncio.gather(return_exceptions=True) returns exceptions for the token or accounts distribution API tasks, the caller in portfolio_command() sets those variables to None. The generate_portfolio_dashboard() function then crashes with:

AttributeError: 'NoneType' object has no attribute 'get'

at line 908 (accounts_distribution_data.get("distribution", [])).

Root Cause

history_data already has a None guard on line 646:

data_points = history_data.get("data", []) if history_data else []

But token_distribution_data (line 843-844) and accounts_distribution_data (line 908-909) are missing the same guard.

Changes

Add if ... else [] / if ... else {} guards to the four .get() calls on token_distribution_data and accounts_distribution_data, consistent with the existing pattern for history_data.

Test Plan

  • Portfolio with all data available: behavior unchanged, all four quadrants render
  • Portfolio with accounts API failure: dashboard renders without account distribution chart instead of crashing
  • Portfolio with token distribution API failure: dashboard renders without token pie chart instead of crashing

Fixes #24

When asyncio.gather returns exceptions for the token or accounts
distribution tasks, the caller sets those variables to None. The
dashboard function then crashes with AttributeError: 'NoneType'
object has no attribute 'get' because it calls .get() without
a None guard.

Add None checks consistent with the existing pattern used for
history_data on line 646, which already handles this correctly.

Fixes hummingbot#24

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Portfolio - Getting AttributeError after loading balances

1 participant