Skip to content

Commit 4f9c19d

Browse files
author
Max Wang
committed
copilot suggestions
1 parent 7e8c194 commit 4f9c19d

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/dataverse_sdk/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,13 @@ def delete_async(
274274
if isinstance(ids, str):
275275
return od._delete_async(logical_name, [ids])
276276
elif isinstance(ids, list):
277-
if not ids:
278-
noop_bulkdelete_job_id = "00000000-0000-0000-0000-000000000000"
279-
return noop_bulkdelete_job_id
280277
if not all(isinstance(rid, str) for rid in ids):
281278
raise TypeError("ids must contain string GUIDs")
282-
return od._delete_async(logical_name, ids)
279+
sanitized = [rid.strip() for rid in ids if isinstance(rid, str) and rid.strip()]
280+
if not sanitized:
281+
noop_bulkdelete_job_id = "00000000-0000-0000-0000-000000000000"
282+
return noop_bulkdelete_job_id
283+
return od._delete_async(logical_name, sanitized)
283284
else:
284285
raise TypeError("ids must be str or list[str]")
285286

src/dataverse_sdk/odata.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,13 @@ def _delete_async(
319319
self,
320320
logical_name: str,
321321
ids: List[str],
322-
) -> Optional[str]:
322+
) -> str:
323323
"""Delete many records by GUID list.
324324
325325
Returns the asynchronous job identifier reported by the BulkDelete action.
326326
"""
327-
targets = [rid for rid in ids if rid]
328-
if not targets:
329-
return None
330-
value_objects = [{"Value": rid, "Type": "System.Guid"} for rid in targets]
327+
noop_job_id = "00000000-0000-0000-0000-000000000000"
328+
value_objects = [{"Value": rid, "Type": "System.Guid"} for rid in ids]
331329

332330
pk_attr = self._primary_id_attr(logical_name)
333331
timestamp = datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
@@ -368,15 +366,16 @@ def _delete_async(
368366
url = f"{self.api}/BulkDelete"
369367
response = self._request("post", url, json=payload, expected=(200, 202, 204))
370368

371-
job_id = None
372369
try:
373370
body = response.json() if response.text else {}
374371
except ValueError:
375372
body = {}
376373
if isinstance(body, dict):
377374
job_id = body.get("JobId")
375+
if isinstance(job_id, str) and job_id.strip():
376+
return job_id
378377

379-
return job_id
378+
return noop_job_id
380379

381380
def _format_key(self, key: str) -> str:
382381
k = key.strip()

0 commit comments

Comments
 (0)