summaryrefslogtreecommitdiff
path: root/docs/api-usage.rst
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-05-02 13:12:11 +0200
committerNejc Habjan <hab.nejc@gmail.com>2021-05-06 20:10:20 +0200
commit38f65e8e9994f58bdc74fe2e0e9b971fc3edf723 (patch)
tree65fc743d58d52c166100abef4886b9bdc41f6315 /docs/api-usage.rst
parent1ddb54a0b4605964477a0d5c5b8a895afe9c3989 (diff)
downloadgitlab-38f65e8e9994f58bdc74fe2e0e9b971fc3edf723.tar.gz
docs(api): add behavior in local attributes when updating objects
Diffstat (limited to 'docs/api-usage.rst')
-rw-r--r--docs/api-usage.rst20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst
index 2a40cfa..e911664 100644
--- a/docs/api-usage.rst
+++ b/docs/api-usage.rst
@@ -407,3 +407,23 @@ parameter to that API invocation:
gl = gitlab.gitlab(url, token, api_version=4)
gl.projects.import_github(ACCESS_TOKEN, 123456, "root", timeout=120.0)
+.. _object_attributes:
+
+Attributes in updated objects
+=============================
+
+When methods manipulate an existing object, such as with ``refresh()`` and ``save()``,
+the object will only have attributes that were returned by the server. In some cases,
+such as when the initial request fetches attributes that are needed later for additional
+processing, this may not be desired:
+
+.. code-block:: python
+
+ project = gl.projects.get(1, statistics=True)
+ project.statistics
+
+ project.refresh()
+ project.statistics # AttributeError
+
+To avoid this, either copy the object/attributes before calling ``refresh()``/``save()``
+or subsequently perform another ``get()`` call as needed, to fetch the attributes you want.