Fix Union deserialization for RecommendationFolder.items#239
Merged
marcelveldt merged 2 commits intoMay 29, 2026
Conversation
mashumaro's default Union deserialization tries types in declaration order and picks the first match (Artist), regardless of the actual media_type. Add field_options(deserialize=...) on RecommendationFolder.items that dispatches to the correct class based on the media_type field value.
github-actions Bot
pushed a commit
to music-assistant/server
that referenced
this pull request
May 29, 2026
Update music-assistant-models to version [1.1.127](https://github.com/music-assistant/models/releases/tag/1.1.127) - Add decoded_audio_format field to StreamDetails (by @marcelveldt in [#240](music-assistant/models#240)) ## 🚀 Features and enhancements - Add artist_str property to Audiobook model (by @jdaberkow in [#234](music-assistant/models#234)) ## 🐛 Bugfixes - Fix Union deserialization for RecommendationFolder.items (by @jdaberkow in [#239](music-assistant/models#239)) ## 🙇 Contributors @jdaberkow and @marcelveldt Co-authored-by: marcelveldt <6389780+marcelveldt@users.noreply.github.com>
jdaberkow
added a commit
to music-assistant/server
that referenced
this pull request
May 30, 2026
…n deserialization The RecommendationFolder.items field now has a custom deserializer (music-assistant/models#239) that discriminates Union types by media_type, so full Playlist/Artist/Album objects survive the to_dict()/from_dict() roundtrip correctly. The ItemMapping conversion workaround is no longer needed. Resolves review issue #18.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mashumaro deserializes Union types by trying each variant in declaration order and picking the first one that doesn't raise. Since
Artisthas the fewest required fields, every item inRecommendationFolder.itemsgets deserialized asArtistregardless of its actualmedia_type.This adds a custom deserializer via
field_options(deserialize=...)that dispatches to the correct class based on themedia_typefield value and the presence ofprovider_mappings(to distinguish fullMediaItemtypes fromItemMapping/BrowseFolder).Includes a roundtrip test covering Artist, Album, Track, Playlist, and ItemMapping.