Skip to content

Commit e5dc799

Browse files
committed
Keep previous input possibilities
1 parent 94370d9 commit e5dc799

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

src/apify_client/_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ def encode_key_value_store_record_value(value: Any, content_type: str | None = N
143143
content_type = 'application/json; charset=utf-8'
144144

145145
if 'application/json' in content_type and not is_file_or_bytes(value) and not isinstance(value, str):
146-
value = _to_json(value).encode('utf-8')
146+
value = json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False, default=str).encode('utf-8')
147147

148-
return value, content_type
149-
150-
151-
def _to_json(value: Any) -> str:
152-
return json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False, default=str)
148+
return (value, content_type)

src/apify_client/clients/resource_clients/actor.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import logging
43
from typing import TYPE_CHECKING, Any
54

65
from apify_shared.utils import (
@@ -10,7 +9,7 @@
109
parse_date_fields,
1110
)
1211

13-
from apify_client._utils import _to_json, encode_webhook_list_to_base64, pluck_data
12+
from apify_client._utils import encode_key_value_store_record_value, encode_webhook_list_to_base64, pluck_data
1413
from apify_client.clients.base import ResourceClient, ResourceClientAsync
1514
from apify_client.clients.resource_clients.actor_version import ActorVersionClient, ActorVersionClientAsync
1615
from apify_client.clients.resource_clients.actor_version_collection import (
@@ -31,7 +30,6 @@
3130

3231
from apify_shared.consts import ActorJobStatus, MetaOrigin
3332

34-
logger = logging.getLogger(__name__)
3533

3634

3735
def get_actor_representation(
@@ -219,7 +217,7 @@ def delete(self) -> None:
219217
def start(
220218
self,
221219
*,
222-
run_input: str | dict | None = None,
220+
run_input: Any = None,
223221
content_type: str | None = None,
224222
build: str | None = None,
225223
max_items: int | None = None,
@@ -235,7 +233,7 @@ def start(
235233
236234
Args:
237235
run_input: The input to pass to the Actor run.
238-
content_type: Deprecated.
236+
content_type: The content type of the input.
239237
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
240238
the run uses the build specified in the default run configuration for the Actor (typically latest).
241239
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -258,11 +256,7 @@ def start(
258256
Returns:
259257
The run object.
260258
"""
261-
if content_type:
262-
logger.warning('`content_type` is deprecated and not used anymore.')
263-
264-
if not isinstance(run_input, str):
265-
run_input = _to_json(run_input)
259+
run_input, content_type = encode_key_value_store_record_value(run_input, content_type)
266260

267261
request_params = self._params(
268262
build=build,
@@ -277,7 +271,7 @@ def start(
277271
response = self.http_client.call(
278272
url=self._url('runs'),
279273
method='POST',
280-
headers={'content-type': 'application/json'},
274+
headers={'content-type': content_type},
281275
data=run_input,
282276
params=request_params,
283277
)
@@ -466,22 +460,22 @@ def webhooks(self) -> WebhookCollectionClient:
466460
"""Retrieve a client for webhooks associated with this Actor."""
467461
return WebhookCollectionClient(**self._sub_resource_init_options())
468462

469-
def validate_input(self, run_input: str | bytes | dict | None = None) -> bool:
463+
def validate_input(self, run_input: Any = None, content_type: str | None = None) -> bool:
470464
"""Validate the input for the Actor.
471465
472466
Args:
473-
run_input: The input to validate. Either json string or a dictionary.
467+
run_input: The input to validate.
468+
content_type: The content type of the input.
474469
475470
Returns:
476471
True if the input is valid, else raise an exception with validation error details.
477472
"""
478-
if not isinstance(run_input, str):
479-
run_input = _to_json(run_input)
473+
run_input, content_type = encode_key_value_store_record_value(run_input, content_type)
480474

481475
self.http_client.call(
482476
url=self._url('validate-input'),
483477
method='POST',
484-
headers={'content-type': 'application/json'},
478+
headers={'content-type': content_type},
485479
data=run_input,
486480
)
487481

@@ -611,7 +605,7 @@ async def delete(self) -> None:
611605
async def start(
612606
self,
613607
*,
614-
run_input: str | dict | None = None,
608+
run_input: Any = None,
615609
content_type: str | None = None,
616610
build: str | None = None,
617611
max_items: int | None = None,
@@ -627,7 +621,7 @@ async def start(
627621
628622
Args:
629623
run_input: The input to pass to the Actor run.
630-
content_type: Deprecated.
624+
content_type: The content type of the input.
631625
build: Specifies the Actor build to run. It can be either a build tag or build number. By default,
632626
the run uses the build specified in the default run configuration for the Actor (typically latest).
633627
max_items: Maximum number of results that will be returned by this run. If the Actor is charged
@@ -650,11 +644,7 @@ async def start(
650644
Returns:
651645
The run object.
652646
"""
653-
if content_type:
654-
logger.warning('`content_type` is deprecated and not used anymore.')
655-
656-
if not isinstance(run_input, str):
657-
run_input = _to_json(run_input)
647+
run_input, content_type = encode_key_value_store_record_value(run_input, content_type)
658648

659649
request_params = self._params(
660650
build=build,
@@ -669,7 +659,7 @@ async def start(
669659
response = await self.http_client.call(
670660
url=self._url('runs'),
671661
method='POST',
672-
headers={'content-type': 'application/json'},
662+
headers={'content-type': content_type},
673663
data=run_input,
674664
params=request_params,
675665
)
@@ -862,22 +852,22 @@ def webhooks(self) -> WebhookCollectionClientAsync:
862852
"""Retrieve a client for webhooks associated with this Actor."""
863853
return WebhookCollectionClientAsync(**self._sub_resource_init_options())
864854

865-
async def validate_input(self, run_input: str | dict | None = None) -> bool:
855+
async def validate_input(self, run_input: Any = None, content_type: str | None = None) -> bool:
866856
"""Validate the input for the Actor.
867857
868858
Args:
869-
run_input: The input to validate. Either json string or a dictionary.
859+
run_input: The input to validate.
860+
content_type: The content type of the input.
870861
871862
Returns:
872863
True if the input is valid, else raise an exception with validation error details.
873864
"""
874-
if not isinstance(run_input, str):
875-
run_input = _to_json(run_input)
865+
run_input, content_type = encode_key_value_store_record_value(run_input, content_type)
876866

877867
await self.http_client.call(
878868
url=self._url('validate-input'),
879869
method='POST',
880-
headers={'content-type': 'application/json'},
870+
headers={'content-type': content_type},
881871
data=run_input,
882872
)
883873

0 commit comments

Comments
 (0)