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-02 13:12:11 +0200
commit796c700cf854b547afb56bb6ea47a5600f437e47 (patch)
treef236a139a844cf055c8fe9769203b481f5380a8a /docs/api-usage.rst
parentb563cdc1a6cd585647fc53722081dceb6f7b4466 (diff)
downloadgitlab-fix/persist-attributes-on-save.tar.gz
fix(base): allow persisting attributes when updating objectfix/persist-attributes-on-save
Diffstat (limited to 'docs/api-usage.rst')
-rw-r--r--docs/api-usage.rst31
1 files changed, 31 insertions, 0 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst
index 2a40cfa..72cb181 100644
--- a/docs/api-usage.rst
+++ b/docs/api-usage.rst
@@ -190,6 +190,37 @@ a project (the previous example used 2 API calls):
project = gl.projects.get(1, lazy=True) # no API call
project.star() # API call
+.. _persist_attributes:
+
+Persisting local attributes
+===========================
+
+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, pass ``persist_attributes=True`` to ``refresh()``/``save()`` calls:
+
+.. code-block:: python
+
+ project = gl.projects.get(1, statistics=True)
+ project.statistics
+
+ project.refresh(persist_attributes=True)
+ project.statistics
+
+The ``persist_attributes`` setting is itself persisted in the object and can be reused
+for later ``refresh()`` and ``save()`` calls.
+
Pagination
==========