diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-05-02 13:12:11 +0200 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2021-05-02 13:12:11 +0200 |
commit | 796c700cf854b547afb56bb6ea47a5600f437e47 (patch) | |
tree | f236a139a844cf055c8fe9769203b481f5380a8a /gitlab/mixins.py | |
parent | b563cdc1a6cd585647fc53722081dceb6f7b4466 (diff) | |
download | gitlab-fix/persist-attributes-on-save.tar.gz |
fix(base): allow persisting attributes when updating objectfix/persist-attributes-on-save
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r-- | gitlab/mixins.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index b9026c5..f0b80ce 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -162,10 +162,12 @@ class RefreshMixin(_RestObjectBase): manager: base.RESTManager @exc.on_http_error(exc.GitlabGetError) - def refresh(self, **kwargs: Any) -> None: + def refresh(self, persist_attributes: bool = None, **kwargs: Any) -> None: """Refresh a single object from server. Args: + persist_attributes: Whether to keep existing local attributes that + were not fetched from the server on refresh **kwargs: Extra options to send to the server (e.g. sudo) Returns None (updates the object) @@ -174,6 +176,9 @@ class RefreshMixin(_RestObjectBase): GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server cannot perform the request """ + if persist_attributes is not None: + self.__dict__["_persist_attrs"] = persist_attributes + if self._id_attr: path = "%s/%s" % (self.manager.path, self.id) else: @@ -529,18 +534,23 @@ class SaveMixin(_RestObjectBase): return updated_data - def save(self, **kwargs: Any) -> None: + def save(self, persist_attributes: bool = None, **kwargs: Any) -> None: """Save the changes made to the object to the server. The object is updated to match what the server returns. Args: + persist_attributes: Whether to keep existing local attributes that + were not fetched from the server on save **kwargs: Extra options to send to the server (e.g. sudo) Raise: GitlabAuthenticationError: If authentication is not correct GitlabUpdateError: If the server cannot perform the request """ + if persist_attributes is not None: + self.__dict__["_persist_attrs"] = persist_attributes + updated_data = self._get_updated_data() # Nothing to update. Server fails if sent an empty dict. if not updated_data: |