Skip to content

Regression on calling len() on GitlabList objects since switching to keyset pagination by default #1114

Closed
@Lucas-C

Description

@Lucas-C

Description of the problem, including code/CLI snippet

Pull request #1110 that has been released in v2.3.0 yesterday introduced a regression on a specific scenario:
when calling len() on the output of Gitlab().projects.list(as_list=False).

Expected Behavior

Being able to call len() on the iterator returned by Gitlab().projects.list(as_list=False)

Actual Behavior

Minimal reproduction code:

import gitlab
len(gitlab.Gitlab(...).projects.list(as_list=False))

Output:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    len(gitlab.Gitlab(...).projects.list(as_list=False))#, pagination='offset'))
  File ".../lib/python3.7/site-packages/gitlab/base.py", line 184, in __len__
    return len(self._list)
  File ".../lib/python3.7/site-packages/gitlab/__init__.py", line 863, in __len__
    return int(self._total)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Workaround:

import gitlab
len(gitlab.Gitlab(...).projects.list(as_list=False, pagination='offset'))

Specifications

  • python-gitlab version: sicnce v2.3.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 12.10.7-ee (80b99e43cfc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions