Skip to content

Commit bae6ae1

Browse files
ensure blob_str enters as bytes
1 parent cf0c0d3 commit bae6ae1

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

label_studio/io_storages/azure_blob/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def get_data(self, key) -> list[StorageObjectParams]:
222222

223223
container = self.get_container()
224224
blob = container.download_blob(key)
225-
blob_str = blob.content_as_text()
225+
blob_str = blob.content_as_bytes()
226226
return load_tasks_json(blob_str, key)
227227

228228
def scan_and_create_links(self):

label_studio/io_storages/localfiles/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ def get_data(self, key) -> list[StorageObjectParams]:
9393

9494
try:
9595
with open(path, 'rb') as f:
96-
blob_str = f.read().decode('utf-8')
96+
blob_str = f.read()
9797
return load_tasks_json(blob_str, key)
98-
except UnicodeDecodeError as e:
99-
raise ValueError(f'Failed to decode file {path} as UTF-8: {str(e)}')
10098
except OSError as e:
10199
raise ValueError(f'Failed to read file {path}: {str(e)}')
102100

label_studio/io_storages/redis/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def get_data(self, key) -> list[StorageObjectParams]:
9595
value_str = client.get(key)
9696
if not value_str:
9797
return []
98-
return load_tasks_json(value_str, key)
98+
blob_str = value_str.encode('utf-8')
99+
return load_tasks_json(blob_str, key)
99100

100101
def scan_and_create_links(self):
101102
return self._scan_and_create_links(RedisImportStorageLink)

label_studio/io_storages/s3/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def get_data(self, key) -> list[StorageObjectParams]:
227227
# read task json from bucket and validate it
228228
_, s3 = self.get_client_and_resource()
229229
bucket = s3.Bucket(self.bucket)
230-
obj = s3.Object(bucket.name, key).get()['Body'].read().decode('utf-8')
230+
obj = s3.Object(bucket.name, key).get()['Body'].read()
231231
return load_tasks_json(obj, key)
232232

233233
@catch_and_reraise_from_none

label_studio/io_storages/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ def bulk_create(
139139
]
140140

141141

142-
def _load_tasks_json(blob_str: str, key: str) -> list[StorageObjectParams]:
142+
def _load_tasks_json(blob_str: bytes, key: str) -> list[StorageObjectParams]:
143143
"""
144144
Parse blob_str containing task JSON(s) and return the validated result or raise an error.
145145
146146
Args:
147-
blob_str (str): The blob string to parse.
147+
blob_str (bytes): The blob string to parse.
148148
key (str): The key of the blob. Used for error messages.
149149
150150
Returns:

0 commit comments

Comments
 (0)