Skip to content

Commit e30f39d

Browse files
nejchJohnVillalovos
authored andcommitted
fix(services): use slug for id_attr instead of custom methods
1 parent 2adf31d commit e30f39d

File tree

1 file changed

+3
-49
lines changed

1 file changed

+3
-49
lines changed

gitlab/v4/objects/services.py

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
https://docs.gitlab.com/ee/api/integrations.html
44
"""
55

6-
from typing import Any, cast, Dict, List, Optional, Union
6+
from typing import Any, cast, List, Union
77

88
from gitlab import cli
99
from gitlab.base import RESTManager, RESTObject
@@ -23,7 +23,7 @@
2323

2424

2525
class ProjectService(SaveMixin, ObjectDeleteMixin, RESTObject):
26-
pass
26+
_id_attr = "slug"
2727

2828

2929
class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTManager):
@@ -264,53 +264,7 @@ class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTM
264264
def get(
265265
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
266266
) -> ProjectService:
267-
"""Retrieve a single object.
268-
269-
Args:
270-
id: ID of the object to retrieve
271-
lazy: If True, don't request the server, but create a
272-
shallow object giving access to the managers. This is
273-
useful if you want to avoid useless calls to the API.
274-
**kwargs: Extra options to send to the server (e.g. sudo)
275-
276-
Returns:
277-
The generated RESTObject.
278-
279-
Raises:
280-
GitlabAuthenticationError: If authentication is not correct
281-
GitlabGetError: If the server cannot perform the request
282-
"""
283-
obj = cast(
284-
ProjectService,
285-
super().get(id, lazy=lazy, **kwargs),
286-
)
287-
obj.id = id
288-
return obj
289-
290-
def update(
291-
self,
292-
id: Optional[Union[str, int]] = None,
293-
new_data: Optional[Dict[str, Any]] = None,
294-
**kwargs: Any
295-
) -> Dict[str, Any]:
296-
"""Update an object on the server.
297-
298-
Args:
299-
id: ID of the object to update (can be None if not required)
300-
new_data: the update data for the object
301-
**kwargs: Extra options to send to the server (e.g. sudo)
302-
303-
Returns:
304-
The new object data (*not* a RESTObject)
305-
306-
Raises:
307-
GitlabAuthenticationError: If authentication is not correct
308-
GitlabUpdateError: If the server cannot perform the request
309-
"""
310-
new_data = new_data or {}
311-
result = super().update(id, new_data, **kwargs)
312-
self.id = id
313-
return result
267+
return cast(ProjectService, super().get(id=id, lazy=lazy, **kwargs))
314268

315269
@cli.register_custom_action("ProjectServiceManager")
316270
def available(self, **kwargs: Any) -> List[str]:

0 commit comments

Comments
 (0)