@@ -162,10 +162,12 @@ class RefreshMixin(_RestObjectBase):
162162 manager : base .RESTManager
163163
164164 @exc .on_http_error (exc .GitlabGetError )
165- def refresh (self , ** kwargs : Any ) -> None :
165+ def refresh (self , persist_attributes : bool = None , ** kwargs : Any ) -> None :
166166 """Refresh a single object from server.
167167
168168 Args:
169+ persist_attributes: Whether to keep existing local attributes that
170+ were not fetched from the server on refresh
169171 **kwargs: Extra options to send to the server (e.g. sudo)
170172
171173 Returns None (updates the object)
@@ -174,6 +176,9 @@ def refresh(self, **kwargs: Any) -> None:
174176 GitlabAuthenticationError: If authentication is not correct
175177 GitlabGetError: If the server cannot perform the request
176178 """
179+ if persist_attributes is not None :
180+ self .__dict__ ["_persist_attrs" ] = persist_attributes
181+
177182 if self ._id_attr :
178183 path = "%s/%s" % (self .manager .path , self .id )
179184 else :
@@ -529,18 +534,23 @@ def _get_updated_data(self) -> Dict[str, Any]:
529534
530535 return updated_data
531536
532- def save (self , ** kwargs : Any ) -> None :
537+ def save (self , persist_attributes : bool = None , ** kwargs : Any ) -> None :
533538 """Save the changes made to the object to the server.
534539
535540 The object is updated to match what the server returns.
536541
537542 Args:
543+ persist_attributes: Whether to keep existing local attributes that
544+ were not fetched from the server on save
538545 **kwargs: Extra options to send to the server (e.g. sudo)
539546
540547 Raise:
541548 GitlabAuthenticationError: If authentication is not correct
542549 GitlabUpdateError: If the server cannot perform the request
543550 """
551+ if persist_attributes is not None :
552+ self .__dict__ ["_persist_attrs" ] = persist_attributes
553+
544554 updated_data = self ._get_updated_data ()
545555 # Nothing to update. Server fails if sent an empty dict.
546556 if not updated_data :
0 commit comments