Skip to content

Commit a877514

Browse files
author
Gauvain Pocentek
committed
Deprecate GetFromListMixin
This mixin provides a workaround for get() for GitLab objects that don't implement a 'get a single object' API. We are now getting conflicts because GitLab adds GET methods, and this is against the "Implement only what exists in the API" strategy. Also use the proper GET API call for objects that support it.
1 parent 5335788 commit a877514

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

RELEASE_NOTES.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ Changes from 1.3 to 1.4
2222
* python-gitlab now handles the server rate limiting feature. It will pause for
2323
the required time when reaching the limit (`documentation
2424
<http://python-gitlab.readthedocs.io/en/master/api-usage.html#rate-limits>`__)
25+
* The ``GetFromListMixin.get()`` method is deprecated and will be removed in
26+
the next python-gitlab version. The goal of this mixin/method is to provide a
27+
way to get an object by looping through a list for GitLab objects that don't
28+
support the GET method. The method `is broken
29+
<https://github.com/python-gitlab/python-gitlab/issues/499>`__ and conflicts
30+
with the GET method now supported by some GitLab objects.
31+
32+
You can implement your own method with something like:
33+
34+
.. code-block:: python
35+
36+
def get_from_list(self, id):
37+
for obj in self.list(as_list=False):
38+
if obj.get_id() == id:
39+
return obj
40+
41+
* The ``GroupMemberManager``, ``NamespaceManager`` and ``ProjectBoardManager``
42+
managers now use the GET API from GitLab instead of the
43+
``GetFromListMixin.get()`` method.
44+
2545

2646
Changes from 1.2 to 1.3
2747
=======================

gitlab/mixins.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
import warnings
19+
1820
import gitlab
1921
from gitlab import base
2022
from gitlab import cli
@@ -130,9 +132,13 @@ def list(self, **kwargs):
130132

131133

132134
class GetFromListMixin(ListMixin):
135+
"""This mixin is deprecated."""
136+
133137
def get(self, id, **kwargs):
134138
"""Retrieve a single object.
135139
140+
This Method is deprecated.
141+
136142
Args:
137143
id (int or str): ID of the object to retrieve
138144
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
@@ -144,6 +150,9 @@ def get(self, id, **kwargs):
144150
GitlabAuthenticationError: If authentication is not correct
145151
GitlabGetError: If the server cannot perform the request
146152
"""
153+
warnings.warn('The get() method for this object is deprecated '
154+
'and will be removed in a future version.',
155+
DeprecationWarning)
147156
try:
148157
gen = self.list()
149158
except exc.GitlabListError:

gitlab/v4/objects.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,7 @@ class GroupMember(SaveMixin, ObjectDeleteMixin, RESTObject):
547547
_short_print_attr = 'username'
548548

549549

550-
class GroupMemberManager(ListMixin, GetMixin, CreateMixin, UpdateMixin,
551-
DeleteMixin, RESTManager):
550+
class GroupMemberManager(CRUDMixin, RESTManager):
552551
_path = '/groups/%(group_id)s/members'
553552
_obj_cls = GroupMember
554553
_from_parent_attrs = {'group_id': 'id'}
@@ -822,7 +821,7 @@ class Namespace(RESTObject):
822821
pass
823822

824823

825-
class NamespaceManager(GetFromListMixin, RESTManager):
824+
class NamespaceManager(RetrieveMixin, RESTManager):
826825
_path = '/namespaces'
827826
_obj_cls = Namespace
828827
_list_filters = ('search', )
@@ -854,7 +853,7 @@ class ProjectBoard(RESTObject):
854853
_managers = (('lists', 'ProjectBoardListManager'), )
855854

856855

857-
class ProjectBoardManager(GetFromListMixin, RESTManager):
856+
class ProjectBoardManager(RetrieveMixin, RESTManager):
858857
_path = '/projects/%(project_id)s/boards'
859858
_obj_cls = ProjectBoard
860859
_from_parent_attrs = {'project_id': 'id'}

0 commit comments

Comments
 (0)