Skip to content

Commit

Permalink
Deprecate GetFromListMixin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Gauvain Pocentek committed May 19, 2018
1 parent 5335788 commit a877514
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
20 changes: 20 additions & 0 deletions RELEASE_NOTES.rst
Expand Up @@ -22,6 +22,26 @@ Changes from 1.3 to 1.4
* python-gitlab now handles the server rate limiting feature. It will pause for
the required time when reaching the limit (`documentation
<http://python-gitlab.readthedocs.io/en/master/api-usage.html#rate-limits>`__)
* The ``GetFromListMixin.get()`` method is deprecated and will be removed in
the next python-gitlab version. The goal of this mixin/method is to provide a
way to get an object by looping through a list for GitLab objects that don't
support the GET method. The method `is broken
<https://github.com/python-gitlab/python-gitlab/issues/499>`__ and conflicts
with the GET method now supported by some GitLab objects.

You can implement your own method with something like:

.. code-block:: python
def get_from_list(self, id):
for obj in self.list(as_list=False):
if obj.get_id() == id:
return obj
* The ``GroupMemberManager``, ``NamespaceManager`` and ``ProjectBoardManager``
managers now use the GET API from GitLab instead of the
``GetFromListMixin.get()`` method.


Changes from 1.2 to 1.3
=======================
Expand Down
9 changes: 9 additions & 0 deletions gitlab/mixins.py
Expand Up @@ -15,6 +15,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import warnings

import gitlab
from gitlab import base
from gitlab import cli
Expand Down Expand Up @@ -130,9 +132,13 @@ def list(self, **kwargs):


class GetFromListMixin(ListMixin):
"""This mixin is deprecated."""

def get(self, id, **kwargs):
"""Retrieve a single object.
This Method is deprecated.
Args:
id (int or str): ID of the object to retrieve
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
Expand All @@ -144,6 +150,9 @@ def get(self, id, **kwargs):
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server cannot perform the request
"""
warnings.warn('The get() method for this object is deprecated '
'and will be removed in a future version.',
DeprecationWarning)
try:
gen = self.list()
except exc.GitlabListError:
Expand Down
7 changes: 3 additions & 4 deletions gitlab/v4/objects.py
Expand Up @@ -547,8 +547,7 @@ class GroupMember(SaveMixin, ObjectDeleteMixin, RESTObject):
_short_print_attr = 'username'


class GroupMemberManager(ListMixin, GetMixin, CreateMixin, UpdateMixin,
DeleteMixin, RESTManager):
class GroupMemberManager(CRUDMixin, RESTManager):
_path = '/groups/%(group_id)s/members'
_obj_cls = GroupMember
_from_parent_attrs = {'group_id': 'id'}
Expand Down Expand Up @@ -822,7 +821,7 @@ class Namespace(RESTObject):
pass


class NamespaceManager(GetFromListMixin, RESTManager):
class NamespaceManager(RetrieveMixin, RESTManager):
_path = '/namespaces'
_obj_cls = Namespace
_list_filters = ('search', )
Expand Down Expand Up @@ -854,7 +853,7 @@ class ProjectBoard(RESTObject):
_managers = (('lists', 'ProjectBoardListManager'), )


class ProjectBoardManager(GetFromListMixin, RESTManager):
class ProjectBoardManager(RetrieveMixin, RESTManager):
_path = '/projects/%(project_id)s/boards'
_obj_cls = ProjectBoard
_from_parent_attrs = {'project_id': 'id'}
Expand Down

0 comments on commit a877514

Please sign in to comment.