From 1001d934e8c36cc3b14408b46b41030bf705a294 Mon Sep 17 00:00:00 2001 From: Nick Brown Date: Tue, 20 Jan 2026 10:40:31 +0000 Subject: [PATCH 1/2] fix: file save start_branch as a body attribute Passing `start_branch` as kwargs results in it being passed as query argument to the API: ``` send: b'PUT /api/v4/projects/12345678/repository/files/readme.txt?start_branch=main send: b'{"file_path": "readme.txt", "branch": "new_branch", "content": "Modified contents", "commit_message": "File was modified for this new branch"}' ``` which results in error being returned: ``` {"message":"You can only create or edit files when you are on a branch"} ``` It should instead be sent a body attribute, which succeeds in creating the branch during the save. To be sent as body attribute it must be specified as concrete function argument and class attribute instead of just using kwargs Closes: #3318 --- gitlab/v4/objects/files.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index 757d16eeb..3bcf931a2 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -29,6 +29,7 @@ class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject): file_path: str manager: ProjectFileManager content: str # since the `decode()` method uses `self.content` + start_branch: str | None = None def decode(self) -> bytes: """Returns the decoded content of the file. @@ -41,7 +42,11 @@ def decode(self) -> bytes: # NOTE(jlvillal): Signature doesn't match SaveMixin.save() so ignore # type error def save( # type: ignore[override] - self, branch: str, commit_message: str, **kwargs: Any + self, + branch: str, + commit_message: str, + start_branch: str | None = None, + **kwargs: Any, ) -> None: """Save the changes made to the file to the server. @@ -50,6 +55,7 @@ def save( # type: ignore[override] Args: branch: Branch in which the file will be updated commit_message: Message to send with the commit + start_branch: Name of the branch to start the new branch from **kwargs: Extra options to send to the server (e.g. sudo) Raises: @@ -58,6 +64,7 @@ def save( # type: ignore[override] """ self.branch = branch self.commit_message = commit_message + self.start_branch = start_branch self.file_path = utils.EncodedId(self.file_path) super().save(**kwargs) From 4187a69420dd7b2e60c2d833ab246aec745d35cb Mon Sep 17 00:00:00 2001 From: Nick Brown Date: Tue, 20 Jan 2026 10:50:12 +0000 Subject: [PATCH 2/2] fix: actually define project repr_attr While `_repr_attr=` is given to specify the attribute to use to repr the object, that object attribute itself is not actually defined, so tools like PyRight/MyPy complain that: ``` Type of "path_with_namespace" is unknown ``` --- gitlab/v4/objects/projects.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index 035b9b861..751ac4c1f 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -178,6 +178,8 @@ class Project( _repr_attr = "path_with_namespace" _upload_path = "/projects/{id}/uploads" + path_with_namespace: str + access_tokens: ProjectAccessTokenManager accessrequests: ProjectAccessRequestManager additionalstatistics: ProjectAdditionalStatisticsManager