-
Notifications
You must be signed in to change notification settings - Fork 51
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
Prevent unnecessary requests when accessing fields that are not set #106
Comments
Thanks for filing an issue for this. The current implementation checks for the given key/property in "cached" data from the first request. discogs_client/discogs_client/models.py Lines 219 to 243 in 31b7936
One solution might be that we check if the original endpoint matches the resource url of that object, then we can assume that refreshing wont suddenly populate that field and just return Null/default value, thus preventing the extra/unnecessary request. I can look into this at some point this week. That is if you don't want to take a crack at it? Cheers! |
Hey @AnssiAhola, thanks for the explanation and quick reply. I already checked out the code to see if I could fix it, but I don't feel comfortable enough yet with the code base to do it myself. I do believe your proposed solution would solve the problem. By the way, I really like the library! It is a joy to work with, especially with the automatic rate limiting, and the smart 'lazy-fetching'. It has proved very useful so far, so thank you very much! |
@rensbaardman have a look at the linked PR. @AnssiAhola might have improved the request behaviour. It would help us a lot if you find the time to test the branch. If you need assistance with installing from that feature branch I can help. Thanks and all the best! |
Thanks for taking the time to implement a solution! This solves the problem I originally had, so that is great. Unfortunately, I think the implementation has a bug: since a new request will look at the import discogs_client
import logging
logging.basicConfig(level=logging.DEBUG)
client = discogs_client.Client('ExampleApplication/0.1')
artist = client.artist(82730)
print(f'{artist.name=}')
same_artist = client.artist(82730)
print(f'{same_artist.name=}') returns
As you see, the second time we try to fetch the artist, this won't trigger a new download since the I think changing discogs_client/discogs_client/models.py Lines 184 to 191 in 27663e3
And I believe saving the |
Good catch! Fixed it and removed the |
When accessing fields which are not set in the Discogs database (such as the
real_name
for an artist which is not a person), this can lead to an unnecessary extra request.Take this example, where we first access the name, triggering the first request. Then we access the
real_name
(which is not set for The Beatles, since it is not a person), triggering the second request to the same endpoint.This results in the following:
I think the problem lies in the fact that the Discogs API does not return a value (e.g.
None
) when it is not set. Anddiscogs_client
only sets/updates a value when it is explicitly returned by the API.I can see two solutions:
None
(or similar) when they are not returnedThe text was updated successfully, but these errors were encountered: