Skip to content

Cannot update/patch protected branch allowed_to_push/push_access_levels state #2850

Closed as not planned

Description

@nickbroon

Description of the problem, including code/CLI snippet

Breaking out discussion from this Pull Request thread into its own issue.

The Save and Update mixins for protectedbranch doesn't really work for most of it's attributes, as the PATCH/POST api use different values from those return by the API.

The PATCH api requires to send allowed_to_push attribute, but the returned attribute is push_access_levels, as documented in the API and examples: https://docs.gitlab.com/ee/api/protected_branches.html#example-update-a-push_access_level-record

Expected Behavior

To be able to update the `allowed_to_push' GitLab protected branch state.

Actual Behavior

Using the python-gitlab library to modify the push_access_levels attribute that the object has and then calling .save() appears to do nothing, and the python object has no allowed_to_push attribute to modify.

It does work for the basic .allow_force_push protectedbranch attribute, as added and tested in the original Pull Request.

Specifications

  • python-gitlab version: unreleased (a867c48)
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): gitlab.com

Activity

  1. JohnVillalovos commented on May 1, 2024

    @JohnVillalovos
    Member

    I think historically we have left issues like this up to the user to handle. As I think the idea of python-gitlab is to be a thin wrapper over the GitLab API. The positive to doing this is it makes things easier for the users. The negative is that it adds more work for the volunteer developers of python-gitlab to add this and there are other inconsistencies in the upstream API that would thus wanted to be added. And then the maintenance of this if GitLab changes the API.

    This might be a good thing to raise upstream and ask GitLab to resolve this inconsistency.

    Interested to get @nejch opinion about this.

    @nickbroon Off topic, I was in Edinburgh just two days ago 😄 But now back in the Portland, Oregon area.

  2. github-actions commented on Oct 12, 2024

    @github-actions

    This issue was marked stale because it has been open 60 days with no activity. Please remove the stale label or comment on this issue. Otherwise, it will be closed in 15 days.

  3. nickbroon commented on Oct 12, 2024

    @nickbroon
    ContributorAuthor

    The only work around I can think to allow modifying branch permissions is for the user to GET protectedBranch, implement their own translation code from push_access_levels structure to the allowed_to_push and then POST that.

  4. nejch commented on Oct 14, 2024

    @nejch
    Member

    The only work around I can think to allow modifying branch permissions is for the user to GET protectedBranch, implement their own translation code from push_access_levels structure to the allowed_to_push and then POST that.

    @nickbroon this is what I do, yes, I call an update() on the manager itself, when encountering this.

    I'm honestly just afraid we'd deviate from upstream parameters if we were making aliases/mappings between GET and PUT/POST/PATCH endpoints, and then confuse users even more. You wouldn't really be updating push_access_levels if we added a mapping, for example.

    I'm assuming we'd be doing this in a generic way and not for every possible endpoint, similar to how we have _create_attrs, _update_attrs etc, but as a dict for the mapping.

  5. github-actions commented on Dec 14, 2024

    @github-actions

    This issue was marked stale because it has been open 60 days with no activity. Please remove the stale label or comment on this issue. Otherwise, it will be closed in 15 days.

  6. nickbroon commented on Dec 14, 2024

    @nickbroon
    ContributorAuthor

    I don't have permissions to remove the 'stale' label. But feel free to add the 'wont-fix' label and close this; I understand the libraries design decision to not translate between non-symmetric GET and PUSH/PATCH rest API in save/update mixins.

  7. github-actions commented on Feb 14, 2025

    @github-actions

    This issue was marked stale because it has been open 60 days with no activity. Please remove the stale label or comment on this issue. Otherwise, it will be closed in 15 days.

  8. nickbroon commented on Feb 14, 2025

    @nickbroon
    ContributorAuthor

    I don't have permissions to remove the 'stale' label. But feel free to add the 'wont-fix' label and close this; I understand the libraries design decision to not translate between non-symmetric GET and PUSH/PATCH rest API in save/update mixins.

  9. JohnVillalovos commented on Feb 14, 2025

    @JohnVillalovos
    Member

    I don't have permissions to remove the 'stale' label. But feel free to add the 'wont-fix' label and close this; I understand the libraries design decision to not translate between non-symmetric GET and PUSH/PATCH rest API in save/update mixins.

    Thank you. Will do.

  10. locked as resolved and limited conversation to collaborators on Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions