joalla / discogs_client

Continuation of the "Official Python Client for the Discogs API"
https://python3-discogs-client.readthedocs.io
Other
310 stars 50 forks source link

Issue with dicts that come from search function #127

Open veljanin opened 1 year ago

veljanin commented 1 year ago

Hi everyone!

There seems to be an issue with the dicts that are returned when using .data method on the one of the objects resulting from the search function.

For example, the following few lines of code should print the number of items in the dict:

import discogs_client

client = discogs_client.Client(use_agent="USER_AGENT", user_token="USER_TOKEN")
results = client.search("Daft Punk One more time", type="master")

print(len(results[0].data.items()))
print(len(results[1].data.items()))

And the output of this code is:

>>> 34
>>> 19

Oddly, it sometimes happens that all dict items have 19 key-value pairs, including the first one - without even changing the code.

Moreover, when inspecting these 2 dicts, I notice that the last key in the first result is "embed" while in the second it's "community". And even more importantly for my use case, the "artists" key is missing in the all the results except the first one.

I'm using version 2.6 of the python3-discogs-client package with dedicated conda environment using Python 3.8.

Any help here would be appreciated!

rexovas commented 1 year ago

Yeah, I've been having trouble with this too. For example, sometimes release.data["artists"] will result in a KeyError. For the most part I've been successful calling release.refresh() and then checking for the missing keys again, but I've also come across a few cases where the value was truly blank on the release page (e.g. no country specified)

in which case, the key would remain missing even after calling release.refresh(). This behavior is definitely inconsistent considering some attributes like "year' will return as 0 if they don't have a value. I can only assume this has to do with how they're being stored in the discogs db and how discogs API is returning the data.

See https://github.com/joalla/discogs_client/issues/129