|
19 | 19 | Run, |
20 | 20 | ) |
21 | 21 | from apify_client._resource_clients import BuildClient, BuildClientAsync |
| 22 | +from apify_client.errors import ConflictError |
22 | 23 |
|
23 | 24 | if TYPE_CHECKING: |
24 | 25 | from apify_client import ApifyClient, ApifyClientAsync |
@@ -88,27 +89,36 @@ async def test_actor_create_update_delete(client: ApifyClient | ApifyClientAsync |
88 | 89 | actor_name = get_random_resource_name('actor') |
89 | 90 |
|
90 | 91 | # Create actor |
91 | | - created_actor = await maybe_await( |
92 | | - client.actors().create( |
93 | | - name=actor_name, |
94 | | - title='Test Actor', |
95 | | - description='Test actor for integration tests', |
96 | | - versions=[ |
97 | | - { |
98 | | - 'versionNumber': '0.1', |
99 | | - 'sourceType': 'SOURCE_FILES', |
100 | | - 'buildTag': 'latest', |
101 | | - 'sourceFiles': [ |
102 | | - { |
103 | | - 'name': 'main.js', |
104 | | - 'format': 'TEXT', |
105 | | - 'content': 'console.log("Hello")', |
106 | | - } |
107 | | - ], |
108 | | - } |
109 | | - ], |
| 92 | + try: |
| 93 | + created_actor = await maybe_await( |
| 94 | + client.actors().create( |
| 95 | + name=actor_name, |
| 96 | + title='Test Actor', |
| 97 | + description='Test actor for integration tests', |
| 98 | + versions=[ |
| 99 | + { |
| 100 | + 'versionNumber': '0.1', |
| 101 | + 'sourceType': 'SOURCE_FILES', |
| 102 | + 'buildTag': 'latest', |
| 103 | + 'sourceFiles': [ |
| 104 | + { |
| 105 | + 'name': 'main.js', |
| 106 | + 'format': 'TEXT', |
| 107 | + 'content': 'console.log("Hello")', |
| 108 | + } |
| 109 | + ], |
| 110 | + } |
| 111 | + ], |
| 112 | + ) |
110 | 113 | ) |
111 | | - ) |
| 114 | + except ConflictError: |
| 115 | + # The HTTP client retries requests on transient 5xx/network errors (at-least-once delivery), so a create |
| 116 | + # POST can commit server-side on one attempt yet still be retried; the retry then fails with a 409 on the |
| 117 | + # unique name it just took. Recover the Actor the first attempt created instead of flaking on this race. |
| 118 | + user = await maybe_await(client.user().get()) |
| 119 | + assert user is not None |
| 120 | + created_actor = await maybe_await(client.actor(f'{user.username}/{actor_name}').get()) |
| 121 | + |
112 | 122 | assert isinstance(created_actor, Actor) |
113 | 123 | assert created_actor.id is not None |
114 | 124 | assert created_actor.name == actor_name |
|
0 commit comments