Skip to content

fix: avoid IndexError in carbonboard when no project is selected - #1387

Open
NoiceHax wants to merge 1 commit into
mlco2:masterfrom
NoiceHax:fix/issue-918
Open

fix: avoid IndexError in carbonboard when no project is selected#1387
NoiceHax wants to merge 1 commit into
mlco2:masterfrom
NoiceHax:fix/issue-918

Conversation

@NoiceHax

Copy link
Copy Markdown

Description

Data.get_project_summary read project_data[-1] without checking the list had anything in it. Clearing the project dropdown filters the dataframe down to zero rows, so the callback raised IndexError: list index out of range and 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=False on the project dropdown and guarded the default value, so an empty CSV does not crash on startup either. carbonboard_on_api.py calls 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_empty and a non-empty companion test_get_project_summary to tests/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.py gives 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 the on_cloud == "N" path.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

AI Usage Disclosure

  • 🟥 AI-vibecoded: You cannot explain the logic.
  • 🟠 AI-generated: Car analogy : the car drive by itself, you are inside and give instructions.
  • â­� AI-assisted. Car analogy : you drive the car, AI help you find your way.
  • â™»ï¸� No AI used. Car analogy : you drive the car.

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:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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.
@NoiceHax
NoiceHax requested a review from a team as a code owner August 15, 2026 11:18
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.

Error(s) when running carbonboard

1 participant