Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing attributes when getting related resources: get_artist, get_tracks, get_albums, get_episodes... #424

Closed
browniebroke opened this issue Jan 4, 2022 · 0 comments · Fixed by #541

Comments

@browniebroke
Copy link
Owner

browniebroke commented Jan 4, 2022

The Deezer API returns fewer fields when retrieving a resource as a relation than when the resource is returned directly. Exampels include:

If we look at the 2nd example, from the library usage perspective, it can be confusing. The API are supposed to return the same resources, but in some cases they return a "shallow" version, with fewer fields and if the user tries to access the missing ones, they'll get an AttributeError.

In the case of the album's artist, there are 2 ways of getting it:

  1. Album.artist field
  2. Album.get_artist() method

The first one doesn't make any API call to Deezer, however it returns an incomplete object with only the following fields: id, name, picture, picture_small, picture_medium, picture_big, picture_xl. The artist returned is missing a few fields which are type annotated as always present:

nb_album: int
nb_fan: int
radio: bool
tracklist: str

The second way, using the method, returns a full object, at the cost of an extra API call.

It's a problem for a couple of reasons:

  • It's not clear from the library API which way should I use to get the album artist
  • If I'm using the 1st way, I might later get an attribute error due to the wrong type hints
@browniebroke browniebroke changed the title Confusing shallow fields & full methods Missing attributes when getting related resources: get_artist, get_tracks, get_albums, get_episodes... Jul 24, 2022
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 a pull request may close this issue.

1 participant