@@ -162,10 +162,12 @@ class RefreshMixin(_RestObjectBase):
162
162
manager :base .RESTManager
163
163
164
164
@exc .on_http_error (exc .GitlabGetError )
165
- def refresh (self ,** kwargs :Any )-> None :
165
+ def refresh (self ,persist_attributes : bool = None , ** kwargs :Any )-> None :
166
166
"""Refresh a single object from server.
167
167
168
168
Args:
169
+ persist_attributes: Whether to keep existing local attributes that
170
+ were not fetched from the server on refresh
169
171
**kwargs: Extra options to send to the server (e.g. sudo)
170
172
171
173
Returns None (updates the object)
@@ -174,6 +176,9 @@ def refresh(self, **kwargs: Any) -> None:
174
176
GitlabAuthenticationError: If authentication is not correct
175
177
GitlabGetError: If the server cannot perform the request
176
178
"""
179
+ if persist_attributes is not None :
180
+ self .__dict__ ["_persist_attrs" ]= persist_attributes
181
+
177
182
if self ._id_attr :
178
183
path = "%s/%s" % (self .manager .path ,self .id )
179
184
else :
@@ -529,18 +534,23 @@ def _get_updated_data(self) -> Dict[str, Any]:
529
534
530
535
return updated_data
531
536
532
- def save (self ,** kwargs :Any )-> None :
537
+ def save (self ,persist_attributes : bool = None , ** kwargs :Any )-> None :
533
538
"""Save the changes made to the object to the server.
534
539
535
540
The object is updated to match what the server returns.
536
541
537
542
Args:
543
+ persist_attributes: Whether to keep existing local attributes that
544
+ were not fetched from the server on save
538
545
**kwargs: Extra options to send to the server (e.g. sudo)
539
546
540
547
Raise:
541
548
GitlabAuthenticationError: If authentication is not correct
542
549
GitlabUpdateError: If the server cannot perform the request
543
550
"""
551
+ if persist_attributes is not None :
552
+ self .__dict__ ["_persist_attrs" ]= persist_attributes
553
+
544
554
updated_data = self ._get_updated_data ()
545
555
# Nothing to update. Server fails if sent an empty dict.
546
556
if not updated_data :