Skip to content

Commit

Permalink
Merge pull request #1832 from python-gitlab/jlvillal/return_save
Browse files Browse the repository at this point in the history
feat(api): return result from `SaveMixin.save()`
  • Loading branch information
nejch committed Jan 13, 2022
2 parents da30753 + e6258a4 commit 27e0742
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gitlab/mixins.py
Expand Up @@ -525,30 +525,33 @@ def _get_updated_data(self) -> Dict[str, Any]:

return updated_data

def save(self, **kwargs: Any) -> None:
def save(self, **kwargs: Any) -> Optional[Dict[str, Any]]:
"""Save the changes made to the object to the server.
The object is updated to match what the server returns.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Returns:
The new object data (*not* a RESTObject)
Raise:
GitlabAuthenticationError: If authentication is not correct
GitlabUpdateError: If the server cannot perform the request
"""
updated_data = self._get_updated_data()
# Nothing to update. Server fails if sent an empty dict.
if not updated_data:
return
return None

# call the manager
obj_id = self.encoded_id
if TYPE_CHECKING:
assert isinstance(self.manager, UpdateMixin)
server_data = self.manager.update(obj_id, updated_data, **kwargs)
if server_data is not None:
self._update_attrs(server_data)
self._update_attrs(server_data)
return server_data


class ObjectDeleteMixin(_RestObjectBase):
Expand Down

0 comments on commit 27e0742

Please sign in to comment.