darwin-py
darwin-py copied to clipboard
Fix optional properties in LocalFile.serialize_v2()
Problem
I tried to upload a file to a V7 2.0 dataset and wanted to add a tag to it while uploading.
local_file = LocalFile("~/test.png", tags=["some-tag"])
dataset.push([local_file])
While the image is uploaded correctly, no tags are set.
Incorrect behavior of darwin-py==0.8.27
>>> local_file.serialize_v2()
{'slots': [{'file_name': 'test.png', 'slot_name': '0', 'tags': ['some-tag']}],
'name': 'test.png',
'path': '/'}
Fixed behavior
>>> local_file.serialize_v2()
{'slots': [{'file_name': 'test.png', 'slot_name': '0'}],
'name': 'test.png',
'path': '/',
'tags': ['some-tag']}
Solution
Store optional_properties
on the dictionary root instead of slots[0]
(c.f. Register data for proceessing).
Example cURL request from the 2.0 REST API
curl --request POST \
--url https://darwin.v7labs.com/api/v2/teams/my-team/items/register_existing \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"items": [
{
"path": "/",
"name": "test.png",
"slots": [
{
"as_frames": false,
"extract_views": false,
"file_name": "test.png"
}
],
"tags": [
"some-tag"
]
}
],
"options": {
"force_tiling": false,
"ignore_dicom_layout": true
},
"dataset_slug": "my-dataset"
}
'
Changelog
- Fix
LocalFile
serialization for v7 2.0
Additional note: just realized that the REST API does allow for a slot to be tagged as well:
Screenshot from V7 REST API docs
However when uploading just one image/slot, the tag was not applied to the whole image/not visible in the UI.