Sync crashes with TypeError when wellness sportInfo is present-but-null
Problem
_extract_power_model_from_wellness crashes when the wellness record contains "sportInfo": null:
File "sync.py", line 3074, in collect_training_data
power_model = self._extract_power_model_from_wellness(today_wellness)
File "sync.py", line 2809, in _extract_power_model_from_wellness
for sport in sport_info:
TypeError: 'NoneType' object is not iterable
The cause is at sync.py:2804:
sport_info = wellness_data.get("sportInfo", [])
The [] default applies only when the key is absent. The Intervals.icu wellness API returns the key present with a null value, so .get() returns None and line 2809 iterates it.
Reproduction
Any athlete whose wellness records are written by a third-party wellness client. Confirmed against the API:
2026-08-09: 'sportInfo' in record = True | value = None
2026-08-08: 'sportInfo' in record = True | value = None
2026-08-06: 'sportInfo' in record = True | value = None
This is latent for athletes whose today wellness record does not yet exist — _get_todays_wellness catches the fetch exception and returns {}, so the [] default applies and nothing crashes. It becomes a hard sync failure as soon as a record exists for today with a null sportInfo. In my case installing an Apple Health → Intervals.icu wellness sync created those records and broke every subsequent sync.
Athletes with no power meter are the most exposed: sportInfo carries eFTP / W' / P-max, so it is most likely to be null precisely where it is least useful.
Fix
sport_info = wellness_data.get("sportInfo") or []
Same pattern elsewhere
Four more API-sourced reads use the same present-but-null-unsafe form. None are firing for me, but all are reachable from API payloads:
- sync.py:688 —
data.get("icu_intervals", []) - sync.py:3501 —
athlete.get("sportSettings", []) - sync.py:4441 —
activity.get("icu_zone_times", []) - sync.py:4453 —
activity.get("icu_hr_zone_times", [])
Verified against v3.122.
Also authored by Claude, at least this time the PR is decent quality and not overly verbose.
Fixed in 4c73c23 and released in sync.py v3.124 (protocol v11.56).
This fixes the reported sportInfo: null crash, plus two additional instances of the same present-but-null bug:
_extract_power_model_from_wellness — sportInfo _build_sport_thresholds — sportSettings and nested types _build_ftp_timeline — types, where "Ride" in None raised the same TypeError
All four reads now normalize null list fields with or [].
Of the four additional sites reported, sportSettings is included in this fix. The other three do not crash: icu_zone_times and icu_hr_zone_times are immediately guarded by truthiness checks, while icu_intervals is followed by an isinstance(..., list) check. A null icu_intervals value is currently classified as transient rather than no_data, which affects retry behavior; that is separate from this crash and was left unchanged.
Verified offline against baseline and patched versions using null, absent, empty-list, valid-cycling, and valid-non-cycling payloads. All null crash paths now skip cleanly, while valid and already-safe inputs retain identical output. A live double-run also confirmed that the populated path is unaffected.
Thanks for the clear reproduction and API evidence — the distinction between an absent field and a present-but-null field was the key to reproducing this reliably.