Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/api-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ How can I clone the repository of a project?
print(project.attributes) # displays all the attributes
git_url = project.ssh_url_to_repo
subprocess.call(['git', 'clone', git_url])

I get an ``AttributeError`` when accessing attributes after ``save()`` or ``refresh()``.
You are most likely trying to access an attribute that was not returned
by the server on the second request. Please look at the documentation in
:ref:`object_attributes` to see how to avoid this.