You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the problem, including code/CLI snippet
Hello,
First of all thank you for the work done in this project, it is helpful.
I am trying to manage some gitlab configuration with python-gitlab CLI, however I do not find the right syntax to protect a branch. I am struggling with the parameters :
I tried gitlab project-protected-branch create --project-id yyy --name master --code-owner-approval-required=true --allowed-to-merge=xxx but it failed with the same error
Impossible to create object (400: allowed_to_merge is invalid)
It should be a complex structure as it can be a list of user_id or a list of group_id.
Elements in the allowed_to_push / allowed_to_merge / allowed_to_unprotect array should take the form {user_id: integer}, {group_id: integer}, or {access_level: integer}. Each user must have access to the project and each group must have this project shared. These access levels allow more granular control over protected branch access.
An example curl command:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "\
https://gitlab.example.com/api/v4/projects/5/protected_branches?name=*-stable&allowed_to_push%5B%5D%5Buser_id%5D=1"
I see that 1735 got merged, but i'm still getting Impossible to create object (400: allowed_to_push is invalid) error on gitlab --debug --verbose project-protected-branch create --project-id 29 --name main --allowed-to-push '[{"access_level": 0}]'.
I thought the array ALLOWED_TO_MERGE has to follow the API
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.
As an open-source project, we rely on community contributions to
address many of the reported issues. Without a proposed fix or
active work towards a solution it is our policy to close inactive
issues. This is documented in CONTRIBUTING.rst
How to keep this issue open:
If you are still experiencing this issue and are willing to
investigate a fix, please comment and let us know.
If you (or someone else) can propose a pull request with a
solution, that would be fantastic.
Any significant update or active discussion indicating progress
will also prevent closure.
We value your input. If you can help provide a fix, we'd be happy
to keep this issue open and support your efforts.
This issue was closed because it has been marked stale for 15 days
with no activity.
This open-source project relies on community contributions, and
while we value all feedback, we have a limited capacity to address
every issue without a clear path forward.
Currently, this issue hasn't received a proposed fix, and there
hasn't been recent active discussion indicating someone is planning
to work on it. To maintain a manageable backlog and focus our
efforts, we will be closing this issue for now.
This doesn't mean the issue isn't valid or important. If you or
anyone else in the community is willing to investigate and propose
a solution (e.g., by submitting a pull request), please do.
We believe that those who feel a bug is important enough to fix
should ideally be part of the solution. Your contributions are
highly welcome.
Thank you for your understanding and potential future
contributions.
Activity
JohnVillalovos commentedon Dec 6, 2021
How does it not work? Any messages? Silently fails?
angegar commentedon Dec 6, 2021
The error message is Impossible to create object (400: allowed_to_merge is invalid)
Probably because of a wrong synxtax, i do not know how to set the --allowed-to-merge parameter.
JohnVillalovos commentedon Dec 6, 2021
The upstream docs ( https://docs.gitlab.com/ee/api/protected_branches.html#protect-repository-branches ) say that
allowed_to_mergeis a list of integers.So I would think on the command line it would be:
--allowed-to-merge=1your example above saysuser_id: xxxJohnVillalovos commentedon Dec 6, 2021
Sorry, the upstream docs say:
So maybe:
--allowed-to-merge=40would be for maintainer access.I'm not quite sure what they mean by "described by a hash"
angegar commentedon Dec 6, 2021
Thank you for your help :D
I tried gitlab project-protected-branch create --project-id yyy --name master --code-owner-approval-required=true --allowed-to-merge=xxx but it failed with the same error
Impossible to create object (400: allowed_to_merge is invalid)
It should be a complex structure as it can be a list of user_id or a list of group_id.
JohnVillalovos commentedon Dec 6, 2021
That doesn't seem to be what the docs say 😟
JohnVillalovos commentedon Dec 6, 2021
If you can figure out how to make it work with a
curlcommand then maybe we can then try to figure out how to make it work with the CLI.JohnVillalovos commentedon Dec 6, 2021
But it seems like it might be what the code says. Confusing 😟
https://gitlab.com/gitlab-org/gitlab/-/blob/1171f6fb3b81c3f7ebaf0a1295eee239e4ea9499/ee/lib/ee/api/helpers/protected_branches_helpers.rb#L21
JohnVillalovos commentedon Dec 7, 2021
Looking more closely at the docs I found:
https://docs.gitlab.com/ee/api/protected_branches.html#example-with-user--group-level-access
Which says:
An example curl command:
Which putting part of it into Python:
So we for sure don't support that data type yet 😟 Right now I have a PR up to better support the
arraytype: #1699We will need to add support for the
hashtype in the future and thearray of hashes.https://docs.gitlab.com/ee/api/#hash
angegar commentedon Dec 7, 2021
OK, thus i have i will have to change my code. Thank you for your investigation.
w7089 commentedon Mar 20, 2023
I see that 1735 got merged, but i'm still getting
Impossible to create object (400: allowed_to_push is invalid)error ongitlab --debug --verbose project-protected-branch create --project-id 29 --name main --allowed-to-push '[{"access_level": 0}]'.I thought the array
ALLOWED_TO_MERGEhas to follow the APIAm I wrong?
The debug mode of the above cli command shows:
github-actions commentedon Jul 9, 2025
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.
As an open-source project, we rely on community contributions to
address many of the reported issues. Without a proposed fix or
active work towards a solution it is our policy to close inactive
issues. This is documented in CONTRIBUTING.rst
How to keep this issue open:
investigate a fix, please comment and let us know.
solution, that would be fantastic.
will also prevent closure.
We value your input. If you can help provide a fix, we'd be happy
to keep this issue open and support your efforts.
This is documented in CONTRIBUTING.rst
https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst
github-actions commentedon Jul 24, 2025
This issue was closed because it has been marked stale for 15 days
with no activity.
This open-source project relies on community contributions, and
while we value all feedback, we have a limited capacity to address
every issue without a clear path forward.
Currently, this issue hasn't received a proposed fix, and there
hasn't been recent active discussion indicating someone is planning
to work on it. To maintain a manageable backlog and focus our
efforts, we will be closing this issue for now.
This doesn't mean the issue isn't valid or important. If you or
anyone else in the community is willing to investigate and propose
a solution (e.g., by submitting a pull request), please do.
We believe that those who feel a bug is important enough to fix
should ideally be part of the solution. Your contributions are
highly welcome.
Thank you for your understanding and potential future
contributions.
This is documented in CONTRIBUTING.rst
https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst