-
Notifications
You must be signed in to change notification settings - Fork 676
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Description of the problem, including code/CLI snippet
project.repository_tree(path="xxx")
throws a 404 exception if the path xxx
doesn't exist. Before it didn't and just returned an empty list. It seems that the behavior changed during last week.
Working example:
import gitlab
from pprint import pprint
# Configuration
SERVER_URL = "https://gitlab.com"
GROUP_ID = 5054009
PROJECT_NAME = "kali-docs"
# Initialization
GL = gitlab.Gitlab(SERVER_URL)
group = GL.groups.get(GROUP_ID)
projects = group.projects.list(all=True)
# Select a project to work with
gproj = [p for p in projects if p.name == PROJECT_NAME][0]
pprint(gproj.attributes)
# Get a "manageable project"
proj = GL.projects.get(gproj.id)
# Get repo tree for a non-existent path
tree = proj.repository_tree(path="non-existent")
It would be nice if someone can confirm this change of behavior.
Expected Behavior
proj.repository_tree(path="non-existent")
used to return an empty list, there was no need to catch any exception.
Actual Behavior
>>> tree = proj.repository_tree(path="non-existent")
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gitlab/exceptions.py", line 337, in wrapped_f
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/gitlab/v4/objects/repositories.py", line 80, in repository_tree
return self.manager.gitlab.http_list(gl_path, query_data=query_data, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/gitlab/client.py", line 944, in http_list
gl_list = GitlabList(self, url, query_data, get_next=False, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/gitlab/client.py", line 1146, in __init__
self._query(url, query_data, **self._kwargs)
File "/usr/lib/python3/dist-packages/gitlab/client.py", line 1156, in _query
result = self._gl.http_request("get", url, query_data=query_data, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/gitlab/client.py", line 800, in http_request
raise gitlab.exceptions.GitlabHttpError(
gitlab.exceptions.GitlabHttpError: 404: 404 invalid revision or path Not Found
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/gitlab/cli.py", line 71, in wrapped_f
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/gitlab/exceptions.py", line 339, in wrapped_f
raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabGetError: 404: 404 invalid revision or path Not Found
Specifications
- python-gitlab version: tested
2.5.0-1
(Debian 11 bullseye) and3.12.0-1
(Debian unstable) - API version you are using (v3/v4): v4
- Gitlab server version (or gitlab.com): gitlab.com