Skip to content

Commit dc30b12

Browse files
authored
feat: add default_run_force_permission_level to Actor update and create (#1111)
`actor.update()` and `actors().create()` (sync and async) get a `default_run_force_permission_level` keyword argument. It sets `defaultRunOptions.forcePermissionLevel`, which the API and the generated models already support. The JS client exposes it through `ActorUpdateOptions`. Split out of #1107, which keeps the two Standby fields. Relates to: #1101 *✍️ Drafted by Claude Code*
1 parent e5d21e5 commit dc30b12

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

‎src/apify_client/_resource_clients/actor.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def update(
120120
default_run_max_items: int | None = None,
121121
default_run_memory_mbytes: int | None = None,
122122
default_run_timeout: timedelta | None = None,
123+
default_run_force_permission_level: ActorPermissionLevel | None = None,
123124
example_run_input_body: str | None = None,
124125
example_run_input_content_type: str | None = None,
125126
actor_standby_is_enabled: bool | None = None,
@@ -156,6 +157,8 @@ def update(
156157
by runs of this Actor, if the Actor is charged per result.
157158
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
158159
default_run_timeout: Default timeout for the runs of this Actor.
160+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
161+
permission level of the Actor.
159162
example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized
160163
as a string (e.g. `json.dumps(input)` for a JSON input).
161164
example_run_input_content_type: The content type of the example run input.
@@ -199,6 +202,7 @@ def update(
199202
max_items=default_run_max_items,
200203
memory_mbytes=default_run_memory_mbytes,
201204
timeout_secs=to_seconds(default_run_timeout, as_int=True),
205+
force_permission_level=default_run_force_permission_level,
202206
restart_on_error=restart_on_error,
203207
),
204208
actor_standby=ActorStandby(
@@ -676,6 +680,7 @@ async def update(
676680
default_run_max_items: int | None = None,
677681
default_run_memory_mbytes: int | None = None,
678682
default_run_timeout: timedelta | None = None,
683+
default_run_force_permission_level: ActorPermissionLevel | None = None,
679684
example_run_input_body: str | None = None,
680685
example_run_input_content_type: str | None = None,
681686
actor_standby_is_enabled: bool | None = None,
@@ -712,6 +717,8 @@ async def update(
712717
by runs of this Actor, if the Actor is charged per result.
713718
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
714719
default_run_timeout: Default timeout for the runs of this Actor.
720+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
721+
permission level of the Actor.
715722
example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized
716723
as a string (e.g. `json.dumps(input)` for a JSON input).
717724
example_run_input_content_type: The content type of the example run input.
@@ -755,6 +762,7 @@ async def update(
755762
max_items=default_run_max_items,
756763
memory_mbytes=default_run_memory_mbytes,
757764
timeout_secs=to_seconds(default_run_timeout, as_int=True),
765+
force_permission_level=default_run_force_permission_level,
758766
restart_on_error=restart_on_error,
759767
),
760768
actor_standby=ActorStandby(

‎src/apify_client/_resource_clients/actor_collection.py‎

Lines changed: 9 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 ActorListItem
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: str | None = None,
127129
example_run_input_content_type: str | None = None,
128130
actor_standby_is_enabled: bool | None = None,
@@ -156,6 +158,8 @@ def create(
156158
of this Actor, if the Actor is charged per result.
157159
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
158160
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.
159163
example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized
160164
as a string (e.g. `json.dumps(input)` for a JSON input).
161165
example_run_input_content_type: The content type of the example run input.
@@ -192,6 +196,7 @@ def create(
192196
max_items=default_run_max_items,
193197
memory_mbytes=default_run_memory_mbytes,
194198
timeout_secs=to_seconds(default_run_timeout, as_int=True),
199+
force_permission_level=default_run_force_permission_level,
195200
restart_on_error=restart_on_error,
196201
),
197202
actor_standby=ActorStandby(
@@ -311,6 +316,7 @@ async def create(
311316
default_run_max_items: int | None = None,
312317
default_run_memory_mbytes: int | None = None,
313318
default_run_timeout: timedelta | None = None,
319+
default_run_force_permission_level: ActorPermissionLevel | None = None,
314320
example_run_input_body: str | None = None,
315321
example_run_input_content_type: str | None = None,
316322
actor_standby_is_enabled: bool | None = None,
@@ -344,6 +350,8 @@ async def create(
344350
of this Actor, if the Actor is charged per result.
345351
default_run_memory_mbytes: Default amount of memory allocated for the runs of this Actor, in megabytes.
346352
default_run_timeout: Default timeout for the runs of this Actor.
353+
default_run_force_permission_level: Permission level to force on the runs of this Actor, overriding the
354+
permission level of the Actor.
347355
example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized
348356
as a string (e.g. `json.dumps(input)` for a JSON input).
349357
example_run_input_content_type: The content type of the example run input.
@@ -380,6 +388,7 @@ async def create(
380388
max_items=default_run_max_items,
381389
memory_mbytes=default_run_memory_mbytes,
382390
timeout_secs=to_seconds(default_run_timeout, as_int=True),
391+
force_permission_level=default_run_force_permission_level,
383392
restart_on_error=restart_on_error,
384393
),
385394
actor_standby=ActorStandby(
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
_EXPECTED_DEFAULT_RUN_OPTIONS = {'forcePermissionLevel': 'FULL_PERMISSIONS'}
38+
39+
40+
def capture(captured: list[Request]) -> Callable[[Request], Response]:
41+
def handler(request: Request) -> Response:
42+
captured.append(request)
43+
return Response(json.dumps(_ACTOR_RESPONSE), status=200, mimetype='application/json')
44+
45+
return handler
46+
47+
48+
def default_run_options_of(request: Request) -> dict[str, Any]:
49+
return json.loads(request.get_data())['defaultRunOptions']
50+
51+
52+
def test_update_sends_force_permission_level(httpserver: HTTPServer, sync_client: ApifyClient) -> None:
53+
"""`update` nests the forced permission level into `defaultRunOptions`."""
54+
captured: list[Request] = []
55+
httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured))
56+
57+
sync_client.actor(_MOCKED_ACTOR_ID).update(default_run_force_permission_level='FULL_PERMISSIONS')
58+
59+
assert len(captured) == 1
60+
assert default_run_options_of(captured[0]) == _EXPECTED_DEFAULT_RUN_OPTIONS
61+
62+
63+
async def test_update_sends_force_permission_level_async(
64+
httpserver: HTTPServer, async_client: ApifyClientAsync
65+
) -> None:
66+
"""Async `update` nests the forced permission level into `defaultRunOptions`."""
67+
captured: list[Request] = []
68+
httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured))
69+
70+
await async_client.actor(_MOCKED_ACTOR_ID).update(default_run_force_permission_level='FULL_PERMISSIONS')
71+
72+
assert len(captured) == 1
73+
assert default_run_options_of(captured[0]) == _EXPECTED_DEFAULT_RUN_OPTIONS
74+
75+
76+
def test_create_sends_force_permission_level(httpserver: HTTPServer, sync_client: ApifyClient) -> None:
77+
"""`create` nests the forced permission level into `defaultRunOptions`."""
78+
captured: list[Request] = []
79+
httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured))
80+
81+
sync_client.actors().create(name='test-actor', default_run_force_permission_level='FULL_PERMISSIONS')
82+
83+
assert len(captured) == 1
84+
assert default_run_options_of(captured[0]) == _EXPECTED_DEFAULT_RUN_OPTIONS
85+
86+
87+
async def test_create_sends_force_permission_level_async(
88+
httpserver: HTTPServer, async_client: ApifyClientAsync
89+
) -> None:
90+
"""Async `create` nests the forced permission level into `defaultRunOptions`."""
91+
captured: list[Request] = []
92+
httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured))
93+
94+
await async_client.actors().create(name='test-actor', default_run_force_permission_level='FULL_PERMISSIONS')
95+
96+
assert len(captured) == 1
97+
assert default_run_options_of(captured[0]) == _EXPECTED_DEFAULT_RUN_OPTIONS

0 commit comments

Comments
 (0)