Skip to content

ProjectMember.save() does not work because 'ProjectMemberAllManager' object has no attribute 'update' #1825

Closed

Description

@theoturner

Description of the problem, including code/CLI snippet

ProjectMember.save() does not work because 'ProjectMemberAllManager' object has no attribute 'update'.

project = GitlabClient().projects.get('my_proj_name')
member = project.members.list()[0]
member.access_level = 30
member.save()

Expected Behavior

Member saves with new properties.
Actual Behavior

Traceback (most recent call last):
  File "gitlab_client.py", line 85, in update_project_permissions
    member.save()
  File "/Users/theoturner/Library/Python/3.8/lib/python/site-packages/gitlab/mixins.py", line 551, in save
    server_data = self.manager.update(obj_id, updated_data, **kwargs)
AttributeError: 'ProjectMemberAllManager' object has no attribute 'update'

N.B. type(member) is <class 'gitlab.v4.objects.members.ProjectMember'> so I haven't accidentally got a ProjectMemberAllManager.
Specifications

python-gitlab version: 3.0.0, can be replicated in 2.8 and above
API version you are using (v3/v4): v4

Note: John Villalovos accidentally edited this and now attempting to return to original state...

Activity

  1. max-wittig commented on Jan 11, 2022

    @max-wittig
    Member

    This is a bit of a conceptional issue. Basically python-gitlab tries to be a small as possible layer on top of the GitLab API as possible. So there is less automatic logic that you might expect, as this reduces complexity of the library a lot

    To update a member, you would need to get the exact member and update this object. You cannot update a list, as python-gitlab in it's principle cannot know what you're trying to update.

    Basically you need to do:

    project = GitlabClient().projects.get('my_proj_name')
    member = project.members.list()[0]
    member = project.members.get(member.id) # add this line
    member.access_level = 30
    member.save()

    Does that clarify the usage?

  2. JohnVillalovos commented on Jan 11, 2022

    @JohnVillalovos
    Member

    @max-wittig @nejch

    This does make me wonder, why can't ProjectMemberAllManager' use a CRUDMixin`?

    Figured it out. Because the path is .../members/all/

  3. JohnVillalovos commented on Jan 11, 2022

    @JohnVillalovos
    Member

    Well we should have a get method based on:

    https://docs.gitlab.com/ee/api/members.html#get-a-member-of-a-group-or-project-including-inherited-and-invited-members Never mind it does.

    As I note if do just a project.members.get(ID) it won't work if the ID is not a direct member of the group.

    In trying as a CRUDMixin save() and others won't work due to the path having /members/all/

  4. JohnVillalovos commented on Jan 11, 2022

    @JohnVillalovos
    Member

    And after saying all that. That is why it has a RetrieveMixin.

    So my theory is that the code should be:

    project = GitlabClient().projects.get('my_proj_name')
    member = project.members_all.list()[0]
    member = project.members_all.get(member.id) # add this line
    member.access_level = 30
    member.save()
    

    Notice everything is members_all

    But not sure that will work. Because still ProjectMemberAllManager 😟

    Really should make sure to use project.members.list() for best results.

  5. JohnVillalovos commented on Jan 11, 2022

    @JohnVillalovos
    Member
    project = GitlabClient().projects.get('my_proj_name')
    member = project.members.list()[0]
    member.access_level = 30
    member.save()
    

    @theoturner I'm assuming that the actual call was member = project.members_all.list() as otherwise I'm not sure how would get a ProjectMemberAllManager

  6. added 12 commits that reference this issue on Jan 12, 2022
    1442e6f
    332cedb
    269a5c7
    6795b48
    f91a329
    89c705a
    497f103
    d6abef8
    4ab12f4
    24b28b6
    88ac96d
    755e0a3
  7. locked as resolved and limited conversation to collaborators on Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions