Skip to content

Commit 1796114

Browse files
committed
feat: add force permission level and missing Standby fields to Actor update and create
1 parent 2397de6 commit 1796114

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

‎src/apify_client/_resource_clients/actor.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def update(
119119
default_run_max_items: int | None = None,
120120
default_run_memory_mbytes: int | None = None,
121121
default_run_timeout: timedelta | None = None,
122+
default_run_force_permission_level: ActorPermissionLevel | None = None,
122123
example_run_input_body: Any = None,
123124
example_run_input_content_type: str | None = None,
124125
actor_standby_is_enabled: bool | None = None,
@@ -127,6 +128,8 @@ def update(
127128
actor_standby_idle_timeout: timedelta | None = None,
128129
actor_standby_build: str | None = None,
129130
actor_standby_memory_mbytes: int | None = None,
131+
actor_standby_disable_standby_fields_override: bool | None = None,
132+
actor_standby_should_pass_actor_input: bool | None = None,
130133
pricing_infos: list[dict[str, Any]] | None = None,
131134
actor_permission_level: ActorPermissionLevel | None = None,
132135
tagged_builds: dict[str, dict[str, str] | None] | None = None,
@@ -153,6 +156,8 @@ def update(
153156
by runs of this Actor, if the Actor is charged per result.
154157
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
155158
default_run_timeout: Default timeout for the runs of this Actor.
159+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
160+
permission level of the Actor.
156161
example_run_input_body: Input to be prefilled as default input to new users of this Actor.
157162
example_run_input_content_type: The content type of the example run input.
158163
actor_standby_is_enabled: Whether the Actor Standby is enabled.
@@ -164,6 +169,10 @@ def update(
164169
it will be shut down.
165170
actor_standby_build: The build tag or number to run when the Actor is in Standby mode.
166171
actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode.
172+
actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being
173+
overridden elsewhere.
174+
actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false,
175+
the Standby runs start with no input.
167176
pricing_infos: A list of objects that describes the pricing of the Actor.
168177
actor_permission_level: The permission level of the Actor on Apify platform.
169178
tagged_builds: A dictionary mapping build tag names to their settings. Use it to create, update,
@@ -191,6 +200,7 @@ def update(
191200
max_items=default_run_max_items,
192201
memory_mbytes=default_run_memory_mbytes,
193202
timeout_secs=to_seconds(default_run_timeout, as_int=True),
203+
force_permission_level=default_run_force_permission_level,
194204
restart_on_error=restart_on_error,
195205
),
196206
actor_standby=ActorStandby(
@@ -200,6 +210,8 @@ def update(
200210
idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True),
201211
build=actor_standby_build,
202212
memory_mbytes=actor_standby_memory_mbytes,
213+
disable_standby_fields_override=actor_standby_disable_standby_fields_override,
214+
should_pass_actor_input=actor_standby_should_pass_actor_input,
203215
),
204216
example_run_input=ExampleRunInput(
205217
body=example_run_input_body,
@@ -653,6 +665,7 @@ async def update(
653665
default_run_max_items: int | None = None,
654666
default_run_memory_mbytes: int | None = None,
655667
default_run_timeout: timedelta | None = None,
668+
default_run_force_permission_level: ActorPermissionLevel | None = None,
656669
example_run_input_body: Any = None,
657670
example_run_input_content_type: str | None = None,
658671
actor_standby_is_enabled: bool | None = None,
@@ -661,6 +674,8 @@ async def update(
661674
actor_standby_idle_timeout: timedelta | None = None,
662675
actor_standby_build: str | None = None,
663676
actor_standby_memory_mbytes: int | None = None,
677+
actor_standby_disable_standby_fields_override: bool | None = None,
678+
actor_standby_should_pass_actor_input: bool | None = None,
664679
pricing_infos: list[dict[str, Any]] | None = None,
665680
actor_permission_level: ActorPermissionLevel | None = None,
666681
tagged_builds: dict[str, dict[str, str] | None] | None = None,
@@ -687,6 +702,8 @@ async def update(
687702
by runs of this Actor, if the Actor is charged per result.
688703
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
689704
default_run_timeout: Default timeout for the runs of this Actor.
705+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
706+
permission level of the Actor.
690707
example_run_input_body: Input to be prefilled as default input to new users of this Actor.
691708
example_run_input_content_type: The content type of the example run input.
692709
actor_standby_is_enabled: Whether the Actor Standby is enabled.
@@ -698,6 +715,10 @@ async def update(
698715
it will be shut down.
699716
actor_standby_build: The build tag or number to run when the Actor is in Standby mode.
700717
actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode.
718+
actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being
719+
overridden elsewhere.
720+
actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false,
721+
the Standby runs start with no input.
701722
pricing_infos: A list of objects that describes the pricing of the Actor.
702723
actor_permission_level: The permission level of the Actor on Apify platform.
703724
tagged_builds: A dictionary mapping build tag names to their settings. Use it to create, update,
@@ -725,6 +746,7 @@ async def update(
725746
max_items=default_run_max_items,
726747
memory_mbytes=default_run_memory_mbytes,
727748
timeout_secs=to_seconds(default_run_timeout, as_int=True),
749+
force_permission_level=default_run_force_permission_level,
728750
restart_on_error=restart_on_error,
729751
),
730752
actor_standby=ActorStandby(
@@ -734,6 +756,8 @@ async def update(
734756
idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True),
735757
build=actor_standby_build,
736758
memory_mbytes=actor_standby_memory_mbytes,
759+
disable_standby_fields_override=actor_standby_disable_standby_fields_override,
760+
should_pass_actor_input=actor_standby_should_pass_actor_input,
737761
),
738762
example_run_input=ExampleRunInput(
739763
body=example_run_input_body,

‎src/apify_client/_resource_clients/actor_collection.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from collections.abc import AsyncIterator, Iterator
2222
from datetime import timedelta
2323

24+
from apify_client._literals import ActorPermissionLevel
2425
from apify_client._models import ActorShort
2526
from apify_client.types import Timeout
2627

@@ -123,6 +124,7 @@ def create(
123124
default_run_max_items: int | None = None,
124125
default_run_memory_mbytes: int | None = None,
125126
default_run_timeout: timedelta | None = None,
127+
default_run_force_permission_level: ActorPermissionLevel | None = None,
126128
example_run_input_body: Any = None,
127129
example_run_input_content_type: str | None = None,
128130
actor_standby_is_enabled: bool | None = None,
@@ -131,6 +133,8 @@ def create(
131133
actor_standby_idle_timeout: timedelta | None = None,
132134
actor_standby_build: str | None = None,
133135
actor_standby_memory_mbytes: int | None = None,
136+
actor_standby_disable_standby_fields_override: bool | None = None,
137+
actor_standby_should_pass_actor_input: bool | None = None,
134138
timeout: Timeout = 'medium',
135139
) -> Actor:
136140
"""Create a new Actor.
@@ -154,6 +158,8 @@ def create(
154158
of this Actor, if the Actor is charged per result.
155159
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
156160
default_run_timeout: Default timeout for the runs of this Actor.
161+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
162+
permission level of the Actor.
157163
example_run_input_body: Input to be prefilled as default input to new users of this Actor.
158164
example_run_input_content_type: The content type of the example run input.
159165
actor_standby_is_enabled: Whether the Actor Standby is enabled.
@@ -165,6 +171,10 @@ def create(
165171
it will be shut down.
166172
actor_standby_build: The build tag or number to run when the Actor is in Standby mode.
167173
actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode.
174+
actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being
175+
overridden elsewhere.
176+
actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false,
177+
the Standby runs start with no input.
168178
timeout: Timeout for the API HTTP request.
169179
170180
Returns:
@@ -185,6 +195,7 @@ def create(
185195
max_items=default_run_max_items,
186196
memory_mbytes=default_run_memory_mbytes,
187197
timeout_secs=to_seconds(default_run_timeout, as_int=True),
198+
force_permission_level=default_run_force_permission_level,
188199
restart_on_error=restart_on_error,
189200
),
190201
actor_standby=ActorStandby(
@@ -194,6 +205,8 @@ def create(
194205
idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True),
195206
build=actor_standby_build,
196207
memory_mbytes=actor_standby_memory_mbytes,
208+
disable_standby_fields_override=actor_standby_disable_standby_fields_override,
209+
should_pass_actor_input=actor_standby_should_pass_actor_input,
197210
),
198211
example_run_input=ExampleRunInput(
199212
body=example_run_input_body,
@@ -302,6 +315,7 @@ async def create(
302315
default_run_max_items: int | None = None,
303316
default_run_memory_mbytes: int | None = None,
304317
default_run_timeout: timedelta | None = None,
318+
default_run_force_permission_level: ActorPermissionLevel | None = None,
305319
example_run_input_body: Any = None,
306320
example_run_input_content_type: str | None = None,
307321
actor_standby_is_enabled: bool | None = None,
@@ -310,6 +324,8 @@ async def create(
310324
actor_standby_idle_timeout: timedelta | None = None,
311325
actor_standby_build: str | None = None,
312326
actor_standby_memory_mbytes: int | None = None,
327+
actor_standby_disable_standby_fields_override: bool | None = None,
328+
actor_standby_should_pass_actor_input: bool | None = None,
313329
timeout: Timeout = 'medium',
314330
) -> Actor:
315331
"""Create a new Actor.
@@ -333,6 +349,8 @@ async def create(
333349
of this Actor, if the Actor is charged per result.
334350
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
335351
default_run_timeout: Default timeout for the runs of this Actor.
352+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
353+
permission level of the Actor.
336354
example_run_input_body: Input to be prefilled as default input to new users of this Actor.
337355
example_run_input_content_type: The content type of the example run input.
338356
actor_standby_is_enabled: Whether the Actor Standby is enabled.
@@ -344,6 +362,10 @@ async def create(
344362
it will be shut down.
345363
actor_standby_build: The build tag or number to run when the Actor is in Standby mode.
346364
actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode.
365+
actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being
366+
overridden elsewhere.
367+
actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false,
368+
the Standby runs start with no input.
347369
timeout: Timeout for the API HTTP request.
348370
349371
Returns:
@@ -364,6 +386,7 @@ async def create(
364386
max_items=default_run_max_items,
365387
memory_mbytes=default_run_memory_mbytes,
366388
timeout_secs=to_seconds(default_run_timeout, as_int=True),
389+
force_permission_level=default_run_force_permission_level,
367390
restart_on_error=restart_on_error,
368391
),
369392
actor_standby=ActorStandby(
@@ -373,6 +396,8 @@ async def create(
373396
idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True),
374397
build=actor_standby_build,
375398
memory_mbytes=actor_standby_memory_mbytes,
399+
disable_standby_fields_override=actor_standby_disable_standby_fields_override,
400+
should_pass_actor_input=actor_standby_should_pass_actor_input,
376401
),
377402
example_run_input=ExampleRunInput(
378403
body=example_run_input_body,
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
from __future__ import annotations
2+
3+
import json
4+
from typing import TYPE_CHECKING, Any
5+
6+
import pytest
7+
from werkzeug import Request, Response
8+
9+
if TYPE_CHECKING:
10+
from collections.abc import Callable
11+
12+
from pytest_httpserver import HTTPServer
13+
14+
from apify_client import ApifyClient, ApifyClientAsync
15+
16+
pytestmark = pytest.mark.usefixtures('http_client_classes')
17+
18+
_MOCKED_ACTOR_ID = 'test_actor_id'
19+
_ACTOR_PATH = f'/v2/actors/{_MOCKED_ACTOR_ID}'
20+
_ACTORS_PATH = '/v2/actors'
21+
22+
_ACTOR_RESPONSE = {
23+
'data': {
24+
'id': _MOCKED_ACTOR_ID,
25+
'userId': 'test_user_id',
26+
'name': 'test-actor',
27+
'username': 'test-user',
28+
'isPublic': False,
29+
'createdAt': '2026-08-01T10:00:00.000Z',
30+
'modifiedAt': '2026-08-01T10:00:00.000Z',
31+
'stats': {},
32+
'versions': [],
33+
'defaultRunOptions': {},
34+
}
35+
}
36+
37+
_FIELDS: dict[str, Any] = {
38+
'default_run_force_permission_level': 'FULL_PERMISSIONS',
39+
'actor_standby_disable_standby_fields_override': True,
40+
'actor_standby_should_pass_actor_input': False,
41+
}
42+
43+
_EXPECTED_BODY = {
44+
'defaultRunOptions': {'forcePermissionLevel': 'FULL_PERMISSIONS'},
45+
'actorStandby': {'disableStandbyFieldsOverride': True, 'shouldPassActorInput': False},
46+
}
47+
48+
49+
def capture(captured: list[Request]) -> Callable[[Request], Response]:
50+
def handler(request: Request) -> Response:
51+
captured.append(request)
52+
return Response(json.dumps(_ACTOR_RESPONSE), status=200, mimetype='application/json')
53+
54+
return handler
55+
56+
57+
def body_subset(request: Request) -> dict[str, Any]:
58+
body = json.loads(request.get_data())
59+
return {key: body[key] for key in _EXPECTED_BODY}
60+
61+
62+
def test_update_sends_permission_and_standby_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None:
63+
"""`update` nests the forced permission level and the Standby flags into the request body."""
64+
captured: list[Request] = []
65+
httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured))
66+
67+
sync_client.actor(_MOCKED_ACTOR_ID).update(**_FIELDS)
68+
69+
assert len(captured) == 1
70+
assert body_subset(captured[0]) == _EXPECTED_BODY
71+
72+
73+
async def test_update_sends_permission_and_standby_fields_async(
74+
httpserver: HTTPServer, async_client: ApifyClientAsync
75+
) -> None:
76+
"""Async `update` nests the forced permission level and the Standby flags into the request body."""
77+
captured: list[Request] = []
78+
httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured))
79+
80+
await async_client.actor(_MOCKED_ACTOR_ID).update(**_FIELDS)
81+
82+
assert len(captured) == 1
83+
assert body_subset(captured[0]) == _EXPECTED_BODY
84+
85+
86+
def test_create_sends_permission_and_standby_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None:
87+
"""`create` nests the forced permission level and the Standby flags into the request body."""
88+
captured: list[Request] = []
89+
httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured))
90+
91+
sync_client.actors().create(name='test-actor', **_FIELDS)
92+
93+
assert len(captured) == 1
94+
assert body_subset(captured[0]) == _EXPECTED_BODY
95+
96+
97+
async def test_create_sends_permission_and_standby_fields_async(
98+
httpserver: HTTPServer, async_client: ApifyClientAsync
99+
) -> None:
100+
"""Async `create` nests the forced permission level and the Standby flags into the request body."""
101+
captured: list[Request] = []
102+
httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured))
103+
104+
await async_client.actors().create(name='test-actor', **_FIELDS)
105+
106+
assert len(captured) == 1
107+
assert body_subset(captured[0]) == _EXPECTED_BODY

0 commit comments

Comments
 (0)