Skip to content

Fix silent dropping of stints in legacy list format (#863)#872

Open
gabrielrv13 wants to merge 1 commit intotheOehrly:mainfrom
gabrielrv13:fix/legacy-stints-list-format
Open

Fix silent dropping of stints in legacy list format (#863)#872
gabrielrv13 wants to merge 1 commit intotheOehrly:mainfrom
gabrielrv13:fix/legacy-stints-list-format

Conversation

@gabrielrv13
Copy link

Summary

Historic races (approx. 2018–2019) return Stints from the timing app API as a plain list instead of a dict with string indices. The previous parser assumed dict format unconditionally, causing all stints to be silently dropped when a list was received, no error, no warning.

Fixes #863, related to #860.

Root cause

In timing_app_data (fastf1/_api.py), the loop over stints used enumerate(update) and only reassigned stint_number and stint inside an isinstance(update, dict) check. When update was a list, the check was never entered, but the list itself was never normalized, causing downstream code to receive incomplete data.

Fix

Normalize the list format to dict before the loop:

if isinstance(update, list):
    update = {str(i): s for i, s in enumerate(update)}
for stint_number, stint in update.items():
    stint_number = int(stint_number)

This removes the ambiguous isinstance check inside the loop body and makes the two formats converge before any processing happens.

Validation

Tested against:

  • Baku 2018 (legacy list format, lap-1 pit stops): all 5 affected drivers now show correct stint history
  • Baku 2025 (modern dict format, lap-1 pit stops): no regression
  • Monaco 2024 (modern dict format, red flag lap 1): no regression

Tests

Two unit tests added to fastf1/tests/test_api.py:

  • test_timing_app_data_legacy_list_format: verifies list format is parsed correctly and no stints are dropped
  • test_timing_app_data_modern_dict_format: verifies dict format continues to work as before

Historic races (approx. 2018-2019) return Stints from the timing app
API as a plain list instead of a dict with string indices. The previous
parser assumed dict format unconditionally, causing all stints to be
silently dropped when a list was received.

Normalize list format to dict before iteration, and switch the loop
to use .items() directly, removing the ambiguous isinstance check
that was previously inside the loop body.

Fixes theOehrly#863
@theOehrly
Copy link
Owner

@gabrielrv13 thanks for the PR, we will try to take a look at is soon :)

@Casper-Guo do you want to review (if you have time), since you have looked into this issue in more depth already? I only have a superficial grasp of the problem at this point.

@Casper-Guo
Copy link
Contributor

Gladly. This code is some of the oldest in the project and the flow is hard to follow. Haven't really worked with the API module before so I will need to look at the raw data more before I can assess the correctness of the fix as well. Just need to find a bigger chunk of time, hopefully over the next week

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.

[BUG] List format stints in legacy API responses cause dropped stints

3 participants