Skip to content

Conversation

@springfall2008
Copy link
Owner

Copilot AI review requested due to automatic review settings January 9, 2026 19:24
Copy link
Contributor

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

This PR fixes a critical bug in the Solcast solar forecasting code that causes a KeyError crash when day 0 (today) has missing or stale forecast data. The bug was caused by incorrect initialization logic that prevented daily totals from being properly initialized when forecast data was sparse.

Key changes:

  • Fixed initialization loop to properly initialize all 7 days of forecast data
  • Corrected indentation of days tracking variable
  • Added regression test for missing day 0 scenario

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
apps/predbat/solcast.py Fixed initialization bug where days was set to 0 immediately after declaration, preventing the initialization loop from running; now properly initializes all 7 days upfront
apps/predbat/tests/test_solcast.py Added regression test test_publish_pv_stats_missing_day_zero to verify the fix handles missing day 0 forecast data; also added debug logging to existing test
apps/predbat/predbat.py Bumped version from v8.31.13 to v8.31.14

"""Mock log - silent"""
pass
"""Mock log - print for debugging"""
if "DEBUG:" in str(message):
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to the mock log method could cause it to print unintended debug messages. The condition checks if "DEBUG:" is in the message, but this will print any log message containing the substring "DEBUG:", not just the intentional debug prints added in this PR. This could cause noise in test output if the actual code logs messages with "DEBUG:" in them.

Consider either:

  1. Using a more specific prefix like "TEST_DEBUG:" that is unlikely to appear in actual code
  2. Adding a flag to control debug output instead of string matching
  3. Reverting this change and only adding the explicit print statements where needed
Suggested change
if "DEBUG:" in str(message):
if str(message).startswith("DEBUG:"):

Copilot uses AI. Check for mistakes.
Comment on lines 985 to 987
print(f"DEBUG: Before publish_pv_stats, midnight_utc={test_api.solar.midnight_utc}")
test_api.solar.publish_pv_stats(pv_forecast_data, divide_by=1.0, period=30)
print(f"DEBUG: After publish_pv_stats, dashboard_items keys={list(test_api.dashboard_items.keys())}")
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These debug print statements appear to be temporary debugging code that was left in. They don't add value to the test and will clutter test output. Consider removing them or wrapping them in a conditional flag for debug mode only.

Copilot uses AI. Check for mistakes.
@springfall2008 springfall2008 changed the title Fix solcast crash Fix solcast and inverter crashes Jan 9, 2026
@springfall2008 springfall2008 requested a review from Copilot January 9, 2026 19:41
Copy link
Contributor

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Comment on lines +48 to 51
"""Mock log - print for debugging"""
if "DEBUG:" in str(message):
print(message)

Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug logging added to the mock log method will cause all messages containing "DEBUG:" to be printed during test runs. This debug logging should be removed before merging as it's not needed in production and will clutter test output. If debugging is needed during development, it should be controlled by a test flag or removed after debugging is complete.

Suggested change
"""Mock log - print for debugging"""
if "DEBUG:" in str(message):
print(message)
"""Mock log - no-op to avoid noisy debug output in tests"""
return

Copilot uses AI. Check for mistakes.
Comment on lines +753 to +755
if start_time is None or end_time is None:
# Invalid time, return 0,0
return 0, 0
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case to verify that compute_window_minutes and window2minutes correctly handle None inputs, as this defensive check was added to prevent crashes. This would ensure the fix continues to work and prevent regression.

Copilot uses AI. Check for mistakes.
springfall2008 and others added 5 commits January 9, 2026 19:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@springfall2008 springfall2008 merged commit 2adff20 into main Jan 9, 2026
1 check passed
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.

2 participants