Skip to content

Commit 15c1b17

Browse files
fix: support int for parent_id in import_group
This will also fix other use cases where an integer is passed in to MultipartEncoder. Added unit tests to show it works. Closes: #2506
1 parent c907029 commit 15c1b17

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

gitlab/_backends/requests_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def prepare_send_data(
7575
if TYPE_CHECKING:
7676
assert isinstance(post_data, dict)
7777
for k, v in post_data.items():
78-
if isinstance(v, bool):
78+
if isinstance(v, (bool, int)):
7979
post_data[k] = str(int(v))
8080
post_data["file"] = files.get("file")
8181
post_data["avatar"] = files.get("avatar")

gitlab/v4/objects/groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def import_group(
378378
file: BinaryIO,
379379
path: str,
380380
name: str,
381-
parent_id: Optional[str] = None,
381+
parent_id: Optional[Union[int, str]] = None,
382382
**kwargs: Any,
383383
) -> Union[Dict[str, Any], requests.Response]:
384384
"""Import a group from an archive file.
@@ -399,7 +399,7 @@ def import_group(
399399
A representation of the import status.
400400
"""
401401
files = {"file": ("file.tar.gz", file, "application/octet-stream")}
402-
data = {"path": path, "name": name}
402+
data: Dict[str, Any] = {"path": path, "name": name}
403403
if parent_id is not None:
404404
data["parent_id"] = parent_id
405405

tests/unit/_backends/test_requests_backend.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ def test_prepare_send_data_str_parentid(self) -> None:
3434
assert result.json is None
3535
assert result.content_type.startswith("multipart/form-data")
3636
assert isinstance(result.data, MultipartEncoder)
37+
38+
def test_prepare_send_data_int_parentid(self) -> None:
39+
file = "12345"
40+
files = {"file": ("file.tar.gz", file, "application/octet-stream")}
41+
post_data = {"parent_id": 12}
42+
43+
result = requests_backend.RequestsBackend.prepare_send_data(
44+
files=files, post_data=post_data, raw=False
45+
)
46+
assert result.json is None
47+
assert result.content_type.startswith("multipart/form-data")
48+
assert isinstance(result.data, MultipartEncoder)

0 commit comments

Comments
 (0)