Skip to content

Fix KeyError during artist download pagination#277

Merged
glomatico merged 1 commit intoglomatico:mainfrom
LiuqingDu:fix-all-albums
Mar 5, 2026
Merged

Fix KeyError during artist download pagination#277
glomatico merged 1 commit intoglomatico:mainfrom
LiuqingDu:fix-all-albums

Conversation

@LiuqingDu
Copy link
Copy Markdown
Contributor

Pull Request: Fix KeyError during artist download pagination

Problem

When using artist download options like --artist-auto-select all-albums on artists with a large number of releases (triggering the API pagination logic), the downloader would crash with a KeyError: 'id'.

This was caused by the code incorrectly extending the data list with the entire response dictionary (which contains data and next keys) instead of extracting and extending with the nested data list. When the subsequent loop tried to read album_metadata["id"] from that dictionary object, it failed.

Solution

Replaced the erroneous list comprehension with an explicit async for loop that correctly extends the results with extended_data["data"].

# Before (Buggy)
artist_metadata[relation_key][type_key]["data"].extend(
    [
        extended_data
        async for extended_data in self.interface.apple_music_api.extend_api_data(...)
    ]
)

# After (Fixed)
async for extended_data in self.interface.apple_music_api.extend_api_data(...):
    artist_metadata[relation_key][type_key]["data"].extend(extended_data["data"])

This change ensures only album-like objects are in the list and makes the logic consistent with similar pagination handling found elsewhere in the codebase (e.g., in get_collection_download_items).

Testing

Verified by running gamdl on an artist with a large number of singles/albums (e.g., Megan Nicole).

  • Before fix: Process crashed with KeyError: 'id' once pagination was triggered.
  • After fix: Successfully fetched all pages and queued all tracks for download.

@LiuqingDu
Copy link
Copy Markdown
Contributor Author

LiuqingDu commented Feb 28, 2026

I encountered this issue. this fix is made by AI.

test url: https://music.apple.com/us/artist/megan-nicole/380531205

@glomatico glomatico merged commit e77c6b2 into glomatico:main Mar 5, 2026
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