Skip to content

Commit 0d91e12

Browse files
authored
fix: Use DeprecationWarning for deprecated methods and arguments (#802)
Replace `logger.warning(...)` calls with `warnings.warn(..., DeprecationWarning)` for deprecated request queue client arguments (`max_unprocessed_requests_retries`, `min_delay_between_unprocessed_requests_retries`), and also emit a `DeprecationWarning` when `exclusive_start_id` is passed to `list_requests`. Using the `warnings` machinery makes deprecations discoverable by tooling and matches Python conventions.
1 parent dc6cf5c commit 0d91e12

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

src/apify_client/clients/resource_clients/request_queue.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

33
import asyncio
4-
import logging
54
import math
5+
import warnings
66
from collections.abc import Iterable
77
from queue import Queue
88
from typing import TYPE_CHECKING, Any, TypedDict
@@ -23,8 +23,6 @@
2323

2424
from apify_shared.consts import StorageGeneralAccess
2525

26-
logger = logging.getLogger(__name__)
27-
2826
_RQ_MAX_REQUESTS_PER_BATCH = 25
2927
_MAX_PAYLOAD_SIZE_BYTES = 9 * 1024 * 1024 # 9 MB
3028
_SAFETY_BUFFER_PERCENT = 0.01 / 100 # 0.01%
@@ -304,16 +302,25 @@ def batch_add_requests(
304302
max_parallel: Specifies the maximum number of parallel tasks for API calls. This is only applicable
305303
to the async client. For the sync client, this value must be set to 1, as parallel execution
306304
is not supported.
307-
max_unprocessed_requests_retries: Deprecated argument. Will be removed in next major release.
308-
min_delay_between_unprocessed_requests_retries: Deprecated argument. Will be removed in next major release.
305+
max_unprocessed_requests_retries: Deprecated argument. Will be removed in v3.
306+
min_delay_between_unprocessed_requests_retries: Deprecated argument. Will be removed in v3.
309307
310308
Returns:
311309
Result containing lists of processed and unprocessed requests.
312310
"""
313311
if max_unprocessed_requests_retries:
314-
logger.warning('`max_unprocessed_requests_retries` is deprecated and not used anymore.')
312+
warnings.warn(
313+
'The `max_unprocessed_requests_retries` argument is deprecated and will be removed in v3.',
314+
DeprecationWarning,
315+
stacklevel=2,
316+
)
315317
if min_delay_between_unprocessed_requests_retries:
316-
logger.warning('`min_delay_between_unprocessed_requests_retries` is deprecated and not used anymore.')
318+
warnings.warn(
319+
'The `min_delay_between_unprocessed_requests_retries` argument is deprecated and will be removed '
320+
'in v3.',
321+
DeprecationWarning,
322+
stacklevel=2,
323+
)
317324

318325
if max_parallel != 1:
319326
raise NotImplementedError('max_parallel is only supported in async client')
@@ -393,8 +400,15 @@ def list_requests(
393400
394401
Args:
395402
limit: How many requests to retrieve.
396-
exclusive_start_id: All requests up to this one (including) are skipped from the result.
403+
exclusive_start_id: Deprecated argument. Will be removed in v3.
397404
"""
405+
if exclusive_start_id is not None:
406+
warnings.warn(
407+
'The `exclusive_start_id` argument is deprecated and will be removed in v3.',
408+
DeprecationWarning,
409+
stacklevel=2,
410+
)
411+
398412
request_params = self._params(limit=limit, exclusiveStartId=exclusive_start_id, clientKey=self.client_key)
399413

400414
response = self.http_client.call(
@@ -731,16 +745,25 @@ async def batch_add_requests(
731745
max_parallel: Specifies the maximum number of parallel tasks for API calls. This is only applicable
732746
to the async client. For the sync client, this value must be set to 1, as parallel execution
733747
is not supported.
734-
max_unprocessed_requests_retries: Deprecated argument. Will be removed in next major release.
735-
min_delay_between_unprocessed_requests_retries: Deprecated argument. Will be removed in next major release.
748+
max_unprocessed_requests_retries: Deprecated argument. Will be removed in v3.
749+
min_delay_between_unprocessed_requests_retries: Deprecated argument. Will be removed in v3.
736750
737751
Returns:
738752
Result containing lists of processed and unprocessed requests.
739753
"""
740754
if max_unprocessed_requests_retries:
741-
logger.warning('`max_unprocessed_requests_retries` is deprecated and not used anymore.')
755+
warnings.warn(
756+
'The `max_unprocessed_requests_retries` argument is deprecated and will be removed in v3.',
757+
DeprecationWarning,
758+
stacklevel=2,
759+
)
742760
if min_delay_between_unprocessed_requests_retries:
743-
logger.warning('`min_delay_between_unprocessed_requests_retries` is deprecated and not used anymore.')
761+
warnings.warn(
762+
'The `min_delay_between_unprocessed_requests_retries` argument is deprecated and will be removed '
763+
'in v3.',
764+
DeprecationWarning,
765+
stacklevel=2,
766+
)
744767

745768
tasks = set[asyncio.Task]()
746769
queue: asyncio.Queue[Iterable[dict]] = asyncio.Queue()
@@ -821,8 +844,15 @@ async def list_requests(
821844
822845
Args:
823846
limit: How many requests to retrieve.
824-
exclusive_start_id: All requests up to this one (including) are skipped from the result.
847+
exclusive_start_id: Deprecated argument. Will be removed in v3.
825848
"""
849+
if exclusive_start_id is not None:
850+
warnings.warn(
851+
'The `exclusive_start_id` argument is deprecated and will be removed in v3.',
852+
DeprecationWarning,
853+
stacklevel=2,
854+
)
855+
826856
request_params = self._params(limit=limit, exclusiveStartId=exclusive_start_id, clientKey=self.client_key)
827857

828858
response = await self.http_client.call(

0 commit comments

Comments
 (0)