atlassian-python-api
atlassian-python-api copied to clipboard
Bitbucket: Limit argument does not work for get_commits method
Affected versions: 3.20.0, 3.20.1
Version 3.19.0 (works as expected)
# note limit
get_one_commit = self.bitbucket.get_commits (
project_key,
repository_name,
limit=1,
hash_newest='refs/heads/master'
)
print(type(get_one_commit))
# <class 'list'>
print(len(get_one_commit))
# 1
Version 3.20.0
# note limit
get_one_commit = self.bitbucket.get_commits (
project_key,
repository_name,
limit=1,
hash_newest='refs/heads/master'
)
print(type(get_one_commit))
# <class 'generator'>
Version 3.20.1
# note limit
get_one_commit = self.bitbucket.get_commits (
project_key,
repository_name,
limit=1,
hash_newest='refs/heads/master'
)
print(type(get_one_commit))
# <class 'generator'>
Works as expected. Te return value is for iterating. If you want the first value use get_one_commit = list(get_one_commit)[0] or get_one_commit = next(get_one_commit).
The documentation says this:
:param limit: OPTIONAL: The limit of the number of commits to return, this may be restricted by fixed system limits. Default by built-in method: None
That gives me the impression that iterating over the return value should yield at most limit commits, but it sounds like this actually controls the size of the pages requested from the server per HTTP GET under the hood.
It would be useful if this wrapper API implemented the former (perhaps as a new parameter) so clients could use simple for loops without having to count results and break out, but at the very least the documentation should be updated clarify the actual behavior.
With #939 the function was changed to use _get_paged instead of get and the comment wasn't changed. The limit is the number of commits retrieved in one REST API call. If you only want to get the first element you can use:
def get_one_commit(**kwargs):
kwargs["limit"] = 1
return next(self.bitbucket.get_commits(**kwargs))