summaryrefslogtreecommitdiff
path: root/gitlab/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab/__init__.py')
-rw-r--r--gitlab/__init__.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 721106c..421b9eb 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -112,8 +112,8 @@ class Gitlab(object):
# build the "submanagers"
for parent_cls in six.itervalues(globals()):
if (not inspect.isclass(parent_cls)
- or not issubclass(parent_cls, GitlabObject)
- or parent_cls == CurrentUser):
+ or not issubclass(parent_cls, GitlabObject)
+ or parent_cls == CurrentUser):
continue
if not parent_cls.managers:
@@ -312,11 +312,13 @@ class Gitlab(object):
params = extra_attrs.copy()
params.update(kwargs.copy())
- get_all_results = kwargs.get('all', False)
+ catch_recursion_limit = kwargs.get('safe_all', False)
+ get_all_results = (kwargs.get('all', False) is True
+ or catch_recursion_limit)
# Remove these keys to avoid breaking the listing (urls will get too
# long otherwise)
- for key in ['all', 'next_url']:
+ for key in ['all', 'next_url', 'safe_all']:
if key in params:
del params[key]
@@ -334,12 +336,20 @@ class Gitlab(object):
results = [cls(self, item, **params) for item in r.json()
if item is not None]
- if ('next' in r.links and 'url' in r.links['next']
- and get_all_results is True):
- args = kwargs.copy()
- args.update(extra_attrs)
- args['next_url'] = r.links['next']['url']
- results.extend(self.list(cls, **args))
+ try:
+ if ('next' in r.links and 'url' in r.links['next']
+ and get_all_results):
+ args = kwargs.copy()
+ args.update(extra_attrs)
+ args['next_url'] = r.links['next']['url']
+ results.extend(self.list(cls, **args))
+ except Exception as e:
+ # Catch the recursion limit exception if the 'safe_all'
+ # kwarg was provided
+ if not (catch_recursion_limit and
+ "maximum recursion depth exceeded" in str(e)):
+ raise e
+
return results
def _raw_post(self, path_, data=None, content_type=None, **kwargs):