Skip to content

Commit ac60efe

Browse files
vdusekclaude
andcommitted
feat: accept RequestDraft model in batch_delete_requests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f54bb4e commit ac60efe

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/apify_client/_resource_clients/request_queue.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,21 +405,26 @@ def batch_add_requests(
405405
)
406406
).data
407407

408-
def batch_delete_requests(self, requests: list[dict]) -> BatchDeleteResult:
408+
def batch_delete_requests(self, requests: list[dict | RequestDraft]) -> BatchDeleteResult:
409409
"""Delete given requests from the queue.
410410
411411
https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests
412412
413413
Args:
414-
requests: List of the requests to delete.
414+
requests: List of the requests to delete, each as a dictionary or `RequestDraft` model.
415415
"""
416+
requests_as_dicts: list[dict] = [
417+
(RequestDraft.model_validate(r) if isinstance(r, dict) else r).model_dump(by_alias=True, exclude_none=True)
418+
for r in requests
419+
]
420+
416421
request_params = self._build_params(clientKey=self.client_key)
417422

418423
response = self._http_client.call(
419424
url=self._build_url('requests/batch'),
420425
method='DELETE',
421426
params=request_params,
422-
json=requests,
427+
json=requests_as_dicts,
423428
timeout=FAST_OPERATION_TIMEOUT,
424429
)
425430

@@ -880,21 +885,26 @@ async def batch_add_requests(
880885
)
881886
).data
882887

883-
async def batch_delete_requests(self, requests: list[dict]) -> BatchDeleteResult:
888+
async def batch_delete_requests(self, requests: list[dict | RequestDraft]) -> BatchDeleteResult:
884889
"""Delete given requests from the queue.
885890
886891
https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests
887892
888893
Args:
889-
requests: List of the requests to delete.
894+
requests: List of the requests to delete, each as a dictionary or `RequestDraft` model.
890895
"""
896+
requests_as_dicts: list[dict] = [
897+
(RequestDraft.model_validate(r) if isinstance(r, dict) else r).model_dump(by_alias=True, exclude_none=True)
898+
for r in requests
899+
]
900+
891901
request_params = self._build_params(clientKey=self.client_key)
892902

893903
response = await self._http_client.call(
894904
url=self._build_url('requests/batch'),
895905
method='DELETE',
896906
params=request_params,
897-
json=requests,
907+
json=requests_as_dicts,
898908
timeout=FAST_OPERATION_TIMEOUT,
899909
)
900910
result = response_to_dict(response)

0 commit comments

Comments
 (0)