Prevent duplication of GET parameters #60
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.
Hi,
This PR solves an issue with the ncm library's API GET loop.
The problem is in this code block:
The
nexturl returned by the API already has all the query parameters.On the next loop, this line...
...adds the parameters again. But the
requestslib doesn't merge the parameters. Instead it appends duplicate parameters.This continuous until the URL gets too long and fails with the error:
For most requests this error never triggers, because the URL doesn't get long enough, but with requests that use an
__inparameter and 100 IDs, it does happen.Regular non-in requests also suffer from a bigger request then necessary and the associated overhead.
No exception is raised...
Another issue is that in those cases the API doesn't raise any errors. Instead it returns an empty results list.
It seems that currently it's not possible to distinguish between the API returning 0 rows or an error occuring.
I have solved this in my fork by adding...
url = get_url if params is not None: query_string = urlencode(params) url = f'{url}?{query_string}' while url and (len(results) < limit): ncm = self.session.get(url) + ncm.raise_for_status() if not (200 <= ncm.status_code < 300): break self._return_handler(ncm.status_code, ncm.json()['data'], call_type) url = ncm.json()['meta']['next'] for d in ncm.json()['data']: results.append(d)But this would break backwards compatibility and perhaps requires another discussion on how to best handle. So, it's not included in this PR.