Skip to content

Commit af30081

Browse files
committed
Fix create task
1 parent 199336d commit af30081

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/apify_client/_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: openapi.json
3-
# timestamp: 2026-01-09T14:50:55+00:00
3+
# timestamp: 2026-01-13T19:37:26+00:00
44

55
from __future__ import annotations
66

@@ -1159,6 +1159,11 @@ class Task(BaseModel):
11591159
input: Input32 | None = None
11601160

11611161

1162+
class CreateTaskResponse(BaseModel):
1163+
data: Task
1164+
standby_url: Annotated[str | None, Field(alias='standbyUrl')] = None
1165+
1166+
11621167
class Stats51(BaseModel):
11631168
pass
11641169

src/apify_client/_resource_clients/task.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_task_representation(
3737
restart_on_error: bool | None = None,
3838
) -> dict:
3939
"""Get the dictionary representation of a task."""
40-
return {
40+
task_dict = {
4141
'actId': actor_id,
4242
'name': name,
4343
'options': {
@@ -49,14 +49,27 @@ def get_task_representation(
4949
},
5050
'input': task_input,
5151
'title': title,
52-
'actorStandby': {
52+
}
53+
54+
# Only include actorStandby if at least one field is provided
55+
if any(
56+
[
57+
actor_standby_desired_requests_per_actor_run is not None,
58+
actor_standby_max_requests_per_actor_run is not None,
59+
actor_standby_idle_timeout_secs is not None,
60+
actor_standby_build is not None,
61+
actor_standby_memory_mbytes is not None,
62+
]
63+
):
64+
task_dict['actorStandby'] = {
5365
'desiredRequestsPerActorRun': actor_standby_desired_requests_per_actor_run,
5466
'maxRequestsPerActorRun': actor_standby_max_requests_per_actor_run,
5567
'idleTimeoutSecs': actor_standby_idle_timeout_secs,
5668
'build': actor_standby_build,
5769
'memoryMbytes': actor_standby_memory_mbytes,
58-
},
59-
}
70+
}
71+
72+
return task_dict
6073

6174

6275
class TaskClient(ResourceClient):

src/apify_client/_resource_clients/task_collection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING, Any
44

5-
from apify_client._models import Task, TaskShort
5+
from apify_client._models import CreateTaskResponse, Task, TaskShort
66
from apify_client._resource_clients.base import ResourceCollectionClient, ResourceCollectionClientAsync
77
from apify_client._resource_clients.task import get_task_representation
88
from apify_client._utils import filter_out_none_values_recursively
@@ -106,7 +106,7 @@ def create(
106106
)
107107

108108
result = self._create(filter_out_none_values_recursively(task_representation))
109-
return Task.model_validate(result)
109+
return CreateTaskResponse.model_validate(result).data
110110

111111

112112
class TaskCollectionClientAsync(ResourceCollectionClientAsync):
@@ -204,4 +204,4 @@ async def create(
204204
)
205205

206206
result = await self._create(filter_out_none_values_recursively(task_representation))
207-
return Task.model_validate(result)
207+
return CreateTaskResponse.model_validate(result).data

0 commit comments

Comments
 (0)