未验证 提交 3d9c5add 编写于 作者: R Roman Donchenko 提交者: GitHub

SDK: fix string field serialization for multipart/form-data requests (#5479)

Django REST Framework ignores the Content-Type on request body parts, so
it doesn't know that they are JSON-encoded. Instead, it just tries to
decode each part as if it was an `str()`-encoded value.

Change the encoding to match the decoding. The only type this matters
for is `str`, because `json.dumps` and `str` produce different encodings
for `str` values.

Remove `none_type` from the list of encodable types since, to my
knowledge, there's no way to encode a `None` value as a
`multipart/form-data` part in a way that DRF will understand.
上级 47860c9d
......@@ -135,9 +135,14 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Missing source tag in project annotations (<https://github.com/opencv/cvat/pull/5408>)
- Creating a task with a Git repository via the SDK
(<https://github.com/opencv/cvat/issues/4365>)
- Queries via the low-level API using the `multipart/form-data` Content-Type with string fields
(<https://github.com/opencv/cvat/pull/5479>)
### Security
- `Project.import_dataset` not waiting for completion correctly
(<https://github.com/opencv/cvat/pull/5459>)
## \[2.2.0] - 2022-09-12
### Added
- Added ability to delete frames from a job based on (<https://github.com/openvinotoolkit/cvat/pull/4194>)
......
......@@ -126,8 +126,8 @@ class ApiClient(object):
self.default_headers['User-Agent'] = value
def _serialize_post_parameter(self, obj):
if isinstance(obj, (str, int, float, none_type, bool)):
return ('', json.dumps(obj), 'application/json')
if isinstance(obj, (str, int, float, bool)):
return str(obj)
elif isinstance(obj, io.IOBase):
return self._serialize_file(obj)
raise ApiValueError(
......
......@@ -492,6 +492,40 @@ class TestPostTaskData:
(task, _) = api_client.tasks_api.retrieve(task_id)
assert task.size == 4
def test_can_create_task_with_sorting_method(self):
task_spec = {
"name": f"test {self._USERNAME} to create a task with a custom sorting method",
"labels": [
{
"name": "car",
"color": "#ff00ff",
"attributes": [],
}
],
}
image_files = generate_image_files(15)
task_data = {
"client_files": image_files[5:] + image_files[:5], # perturb the order
"image_quality": 70,
"sorting_method": "natural",
}
# Besides testing that the sorting method is applied, this also checks for
# regressions of <https://github.com/opencv/cvat/issues/4962>.
task_id = self._test_create_task(
self._USERNAME, task_spec, task_data, content_type="multipart/form-data"
)
# check that the frames were sorted again
with make_api_client(self._USERNAME) as api_client:
data_meta, _ = api_client.tasks_api.retrieve_data_meta(task_id)
# generate_image_files produces files that are already naturally sorted
for image_file, frame in zip(image_files, data_meta.frames):
assert image_file.name == frame.name
def test_can_get_annotations_from_new_task_with_skeletons(self):
spec = {
"name": f"test admin1 to create a task with skeleton",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册