fix: avoid IndexError in carbonboard when no project is selected - #1387
Open
NoiceHax wants to merge 1 commit into
Open
fix: avoid IndexError in carbonboard when no project is selected#1387NoiceHax wants to merge 1 commit into
NoiceHax wants to merge 1 commit into
Conversation
get_project_summary indexed project_data[-1] without checking the list was populated. Clearing the project dropdown filters the dataframe down to zero rows, so the callback raised IndexError: list index out of range and the page stopped updating. Return a zeroed summary with the same keys when there is no run, so the nine callback outputs still unpack. Also make the dropdown non-clearable and guard the default value so an empty CSV does not crash on startup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Data.get_project_summaryreadproject_data[-1]without checking the list had anything in it. Clearing the project dropdown filters the dataframe down to zero rows, so the callback raisedIndexError: list index out of rangeand the dashboard stopped updating.It now returns a zeroed summary with the same keys when there is no run, so the nine callback outputs still unpack. I also set
clearable=Falseon the project dropdown and guarded the default value, so an empty CSV does not crash on startup either.carbonboard_on_api.pycalls the same two helpers and gets the fix as well.To be clear about scope, this fixes only the IndexError. The asset 404s reported in the same issue were already fixed by #958.
Related Issue
Fixes #918
Motivation and Context
Clearing the dropdown is a normal thing to do in the UI, and one stray click left the board dead until restart. Guarding at the source keeps every caller safe instead of patching one callback.
How Has This Been Tested?
Added
test_get_project_summary_emptyand a non-empty companiontest_get_project_summarytotests/test_viz_data.py. The empty test fails with the reported IndexError before the change and passes after.uv run pytest -vv tests/test_viz_data.py tests/test_viz_units.pygives 10 passed. I also checked by hand that the downstream callbacks survive the zeroed summary: the equivalents render as zero, the regional choropleth falls back to its placeholder row, and the cloud barchart takes theon_cloud == "N"path.Types of changes
AI Usage Disclosure
This patch and its tests were written by an AI agent working from my instructions, and I reviewed the diff and the test run before opening the PR.
Checklist: