Skip to content

fix: handle list response in get_solar_intensity to prevent bulk-update crash - #269

Open
Deyi-dev wants to merge 1 commit into
arpanghosh8453:mainfrom
Deyi-dev:fix/solar-intensity-list-response
Open

fix: handle list response in get_solar_intensity to prevent bulk-update crash#269
Deyi-dev wants to merge 1 commit into
arpanghosh8453:mainfrom
Deyi-dev:fix/solar-intensity-list-response

Conversation

@Deyi-dev

Copy link
Copy Markdown

Problem

get_solar_intensity() assumes get_device_solar_data() returns a dict:

si_all = garmin_obj.get_device_solar_data(GARMIN_DEVICEID, date_str) or {}
if len(si_all.get('solarDailyDataDTOs', [])) > 0:

On some dates Garmin returns a list instead. The or {} guard only covers None/empty (falsy) values — a non-empty list is truthy, so it passes straight through to si_all.get(...) and crashes the whole run:

File ".../garmin_fetch.py", line 1544, in get_solar_intensity
    if len(si_all.get('solarDailyDataDTOs', [])) > 0:
AttributeError: 'list' object has no attribute 'get'

This is fatal during a bulk backfill: one bad date aborts the entire date range. I hit it on 2026-07-08 while backfilling a solar-capable device (Fenix 7 Pro Solar) with solar_intensity in FETCH_SELECTION.

Fix

Normalize the response to the DTO list before indexing, handling both the dict and list shapes (and guarding the element access):

if isinstance(si_all, dict):
    solar_dtos = si_all.get('solarDailyDataDTOs', [])
elif isinstance(si_all, list):
    solar_dtos = si_all
else:
    solar_dtos = []
if len(solar_dtos) > 0 and isinstance(solar_dtos[0], dict):
    si_list = solar_dtos[0].get('solarInputReadings', [])

The dict path is unchanged; the list path no longer crashes; anything unexpected degrades to "no solar data for this date" instead of aborting the run. Verified by re-running the same 30-day backfill end-to-end with zero errors.

…te crash

get_solar_intensity() assumes get_device_solar_data() returns a dict, but
Garmin occasionally returns a list on some dates. The `or {}` guard only
covers falsy values, so a non-empty list passes through to si_all.get(...)
and raises "AttributeError: 'list' object has no attribute 'get'", which
aborts the entire bulk backfill on that one date.

Normalize the response to the DTO list, handling both dict and list shapes
and guarding element access, so the dict path is unchanged, the list path
no longer crashes, and unexpected shapes degrade to "no data for this date"
instead of killing the run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.

1 participant