Skip to content

Commit b0b2113

Browse files
authored
Merge pull request #1448 from python-gitlab/docs/local-object-attributes
docs(api): add behavior in local attributes when updating objects
2 parents 62b544d + 38f65e8 commit b0b2113

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

docs/api-usage.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,23 @@ parameter to that API invocation:
407407
gl = gitlab.gitlab(url, token, api_version=4)
408408
gl.projects.import_github(ACCESS_TOKEN, 123456, "root", timeout=120.0)
409409
410+
.. _object_attributes:
411+
412+
Attributes in updated objects
413+
=============================
414+
415+
When methods manipulate an existing object, such as with ``refresh()`` and ``save()``,
416+
the object will only have attributes that were returned by the server. In some cases,
417+
such as when the initial request fetches attributes that are needed later for additional
418+
processing, this may not be desired:
419+
420+
.. code-block:: python
421+
422+
project = gl.projects.get(1, statistics=True)
423+
project.statistics
424+
425+
project.refresh()
426+
project.statistics # AttributeError
427+
428+
To avoid this, either copy the object/attributes before calling ``refresh()``/``save()``
429+
or subsequently perform another ``get()`` call as needed, to fetch the attributes you want.

docs/faq.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ How can I clone the repository of a project?
3131
print(project.attributes) # displays all the attributes
3232
git_url = project.ssh_url_to_repo
3333
subprocess.call(['git', 'clone', git_url])
34+
35+
I get an ``AttributeError`` when accessing attributes after ``save()`` or ``refresh()``.
36+
You are most likely trying to access an attribute that was not returned
37+
by the server on the second request. Please look at the documentation in
38+
:ref:`object_attributes` to see how to avoid this.

0 commit comments

Comments
 (0)