summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2023-03-04 18:23:25 -0800
committerNejc Habjan <hab.nejc@gmail.com>2023-03-12 11:11:49 +0100
commit90f96acf9e649de9874cec612fc1b49c4a843447 (patch)
tree4727076055cfdc9bdee96f9f0ea2a7e7865ac20f /gitlab
parentf2b5e4fa375e88d6102a8d023ae2fe8206042545 (diff)
downloadgitlab-90f96acf9e649de9874cec612fc1b49c4a843447.tar.gz
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
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/_backends/requests_backend.py12
-rw-r--r--gitlab/v4/objects/groups.py4
2 files changed, 10 insertions, 6 deletions
diff --git a/gitlab/_backends/requests_backend.py b/gitlab/_backends/requests_backend.py
index d70cf42..839b69e 100644
--- a/gitlab/_backends/requests_backend.py
+++ b/gitlab/_backends/requests_backend.py
@@ -70,17 +70,21 @@ class RequestsBackend(protocol.Backend):
if post_data is None:
post_data = {}
else:
- # booleans does not exists for data (neither for MultipartEncoder):
- # cast to string int to avoid: 'bool' object has no attribute 'encode'
+ # When creating a `MultipartEncoder` instance with data-types
+ # which don't have an `encode` method it will cause an error:
+ # object has no attribute 'encode'
+ # So convert common non-string types into strings.
if TYPE_CHECKING:
assert isinstance(post_data, dict)
for k, v in post_data.items():
if isinstance(v, bool):
- post_data[k] = str(int(v))
+ v = int(v)
+ if isinstance(v, (complex, float, int)):
+ post_data[k] = str(v)
post_data["file"] = files.get("file")
post_data["avatar"] = files.get("avatar")
- data = MultipartEncoder(post_data)
+ data = MultipartEncoder(fields=post_data)
return SendData(data=data, content_type=data.content_type)
if raw and post_data:
diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py
index 0eb516f..4dc4fd1 100644
--- a/gitlab/v4/objects/groups.py
+++ b/gitlab/v4/objects/groups.py
@@ -378,7 +378,7 @@ class GroupManager(CRUDMixin, RESTManager):
file: BinaryIO,
path: str,
name: str,
- parent_id: Optional[str] = None,
+ parent_id: Optional[Union[int, str]] = None,
**kwargs: Any,
) -> Union[Dict[str, Any], requests.Response]:
"""Import a group from an archive file.
@@ -399,7 +399,7 @@ class GroupManager(CRUDMixin, RESTManager):
A representation of the import status.
"""
files = {"file": ("file.tar.gz", file, "application/octet-stream")}
- data = {"path": path, "name": name}
+ data: Dict[str, Any] = {"path": path, "name": name}
if parent_id is not None:
data["parent_id"] = parent_id