|
2 | 2 | FAQ
|
3 | 3 | ###
|
4 | 4 |
|
5 |
| -I cannot edit the merge request / issue I've just retrieved |
6 |
| - It is likely that you used a ``MergeRequest``, ``GroupMergeRequest``, |
7 |
| - ``Issue`` or ``GroupIssue`` object. These objects cannot be edited. But you |
8 |
| - can create a new ``ProjectMergeRequest`` or ``ProjectIssue`` object to |
9 |
| - apply changes. For example:: |
| 5 | +General |
| 6 | +------- |
10 | 7 |
|
11 |
| - issue = gl.issues.list()[0] |
12 |
| - project = gl.projects.get(issue.project_id, lazy=True) |
13 |
| - editable_issue = project.issues.get(issue.iid, lazy=True) |
14 |
| - # you can now edit the object |
| 8 | +I cannot edit the merge request / issue I've just retrieved. |
| 9 | +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
15 | 10 |
|
16 |
| - See the :ref:`merge requests example <merge_requests_examples>` and the |
17 |
| - :ref:`issues examples <issues_examples>`. |
| 11 | +It is likely that you used a ``MergeRequest``, ``GroupMergeRequest``, |
| 12 | +``Issue`` or ``GroupIssue`` object. These objects cannot be edited. But you |
| 13 | +can create a new ``ProjectMergeRequest`` or ``ProjectIssue`` object to |
| 14 | +apply changes. For example:: |
18 | 15 |
|
19 |
| -.. _attribute_error_list: |
| 16 | + issue = gl.issues.list()[0] |
| 17 | + project = gl.projects.get(issue.project_id, lazy=True) |
| 18 | + editable_issue = project.issues.get(issue.iid, lazy=True) |
| 19 | + # you can now edit the object |
| 20 | + |
| 21 | +See the :ref:`merge requests example <merge_requests_examples>` and the |
| 22 | +:ref:`issues examples <issues_examples>`. |
20 | 23 |
|
21 |
| -I get an ``AttributeError`` when accessing attributes of an object retrieved via a ``list()`` call. |
22 |
| - Fetching a list of objects, doesn’t always include all attributes in the |
23 |
| - objects. To retrieve an object with all attributes use a ``get()`` call. |
| 24 | +How can I clone the repository of a project? |
| 25 | +"""""""""""""""""""""""""""""""""""""""""""" |
24 | 26 |
|
25 |
| - Example with projects:: |
| 27 | +python-gitlab does not provide an API to clone a project. You have to use a |
| 28 | +git library or call the ``git`` command. |
26 | 29 |
|
27 |
| - for projects in gl.projects.list(): |
28 |
| - # Retrieve project object with all attributes |
29 |
| - project = gl.projects.get(project.id) |
| 30 | +The git URI is exposed in the ``ssh_url_to_repo`` attribute of ``Project`` |
| 31 | +objects. |
30 | 32 |
|
31 |
| -How can I clone the repository of a project? |
32 |
| - python-gitlab doesn't provide an API to clone a project. You have to use a |
33 |
| - git library or call the ``git`` command. |
| 33 | +Example:: |
| 34 | + |
| 35 | + import subprocess |
| 36 | + |
| 37 | + project = gl.projects.create(data) # or gl.projects.get(project_id) |
| 38 | + print(project.attributes) # displays all the attributes |
| 39 | + git_url = project.ssh_url_to_repo |
| 40 | + subprocess.call(['git', 'clone', git_url]) |
| 41 | + |
| 42 | +Not all items are returned from the API |
| 43 | +""""""""""""""""""""""""""""""""""""""" |
| 44 | + |
| 45 | +If you've passed ``all=True`` (or ``--all`` via the CLI) to the API and still cannot see all items returned, |
| 46 | +use ``get_all=True`` (or ``--get-all`` via the CLI) instead. See :ref:`pagination` for more details. |
| 47 | + |
| 48 | +Common errors |
| 49 | +------------- |
| 50 | + |
| 51 | +.. _attribute_error_list: |
| 52 | + |
| 53 | +``AttributeError`` when accessing object attributes retrieved via ``list()`` |
| 54 | +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| 55 | + |
| 56 | +Fetching a list of objects does not always include all attributes in the objects. |
| 57 | +To retrieve an object with all attributes, use a ``get()`` call. |
| 58 | + |
| 59 | +Example with projects:: |
34 | 60 |
|
35 |
| - The git URI is exposed in the ``ssh_url_to_repo`` attribute of ``Project`` |
36 |
| - objects. |
| 61 | + for projects in gl.projects.list(): |
| 62 | + # Retrieve project object with all attributes |
| 63 | + project = gl.projects.get(project.id) |
37 | 64 |
|
38 |
| - Example:: |
| 65 | +``AttributeError`` when accessing attributes after ``save()`` or ``refresh()`` |
| 66 | +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
39 | 67 |
|
40 |
| - import subprocess |
| 68 | +You are most likely trying to access an attribute that was not returned |
| 69 | +by the server on the second request. Please look at the documentation in |
| 70 | +:ref:`object_attributes` to see how to avoid this. |
41 | 71 |
|
42 |
| - project = gl.projects.create(data) # or gl.projects.get(project_id) |
43 |
| - print(project.attributes) # displays all the attributes |
44 |
| - git_url = project.ssh_url_to_repo |
45 |
| - subprocess.call(['git', 'clone', git_url]) |
| 72 | +``TypeError`` when accessing object attributes |
| 73 | +"""""""""""""""""""""""""""""""""""""""""""""" |
46 | 74 |
|
47 |
| -I get an ``AttributeError`` when accessing attributes after ``save()`` or ``refresh()``. |
48 |
| - You are most likely trying to access an attribute that was not returned |
49 |
| - by the server on the second request. Please look at the documentation in |
50 |
| - :ref:`object_attributes` to see how to avoid this. |
| 75 | +When you encounter errors such as ``object is not iterable`` or ``object is not subscriptable`` |
| 76 | +when trying to access object attributes returned from the server, you are most likely trying to |
| 77 | +access an attribute that is shadowed by python-gitlab's own methods or managers. |
51 | 78 |
|
52 |
| -I passed ``all=True`` (or ``--all`` via the CLI) to the API and I still cannot see all items returned. |
53 |
| - Use ``get_all=True`` (or ``--get-all`` via the CLI). See :ref:`pagination` for more details. |
| 79 | +You can use the object's ``attributes`` dictionary to access it directly instead. |
| 80 | +See the :ref:`objects` section for more details on how attributes are exposed. |
0 commit comments