atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Bitbucket: Limit argument does not work for get_commits method

Open davidmorabito opened this issue 3 years ago • 3 comments

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'>

davidmorabito avatar Apr 08 '22 01:04 davidmorabito

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).

Spacetown avatar Apr 08 '22 06:04 Spacetown

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.

seangies avatar May 09 '22 19:05 seangies

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))

Spacetown avatar May 09 '22 19:05 Spacetown