File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments