prefect-client 3.1.15__py3-none-any.whl → 3.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. prefect/_experimental/sla/objects.py +29 -1
  2. prefect/_internal/compatibility/deprecated.py +4 -4
  3. prefect/_internal/compatibility/migration.py +1 -1
  4. prefect/_internal/concurrency/calls.py +1 -2
  5. prefect/_internal/concurrency/cancellation.py +2 -4
  6. prefect/_internal/concurrency/threads.py +3 -3
  7. prefect/_internal/schemas/bases.py +3 -11
  8. prefect/_internal/schemas/validators.py +36 -60
  9. prefect/_result_records.py +235 -0
  10. prefect/_version.py +3 -3
  11. prefect/agent.py +1 -0
  12. prefect/automations.py +4 -8
  13. prefect/blocks/notifications.py +8 -8
  14. prefect/cache_policies.py +2 -0
  15. prefect/client/base.py +7 -8
  16. prefect/client/collections.py +3 -6
  17. prefect/client/orchestration/__init__.py +15 -263
  18. prefect/client/orchestration/_deployments/client.py +14 -6
  19. prefect/client/orchestration/_flow_runs/client.py +10 -6
  20. prefect/client/orchestration/_work_pools/__init__.py +0 -0
  21. prefect/client/orchestration/_work_pools/client.py +598 -0
  22. prefect/client/orchestration/base.py +9 -2
  23. prefect/client/schemas/actions.py +66 -2
  24. prefect/client/schemas/objects.py +22 -50
  25. prefect/client/schemas/schedules.py +7 -18
  26. prefect/client/types/flexible_schedule_list.py +2 -1
  27. prefect/context.py +2 -3
  28. prefect/deployments/flow_runs.py +1 -1
  29. prefect/deployments/runner.py +119 -43
  30. prefect/deployments/schedules.py +7 -1
  31. prefect/engine.py +4 -9
  32. prefect/events/schemas/automations.py +4 -2
  33. prefect/events/utilities.py +15 -13
  34. prefect/exceptions.py +1 -1
  35. prefect/flow_engine.py +8 -8
  36. prefect/flow_runs.py +4 -8
  37. prefect/flows.py +30 -22
  38. prefect/infrastructure/__init__.py +1 -0
  39. prefect/infrastructure/base.py +1 -0
  40. prefect/infrastructure/provisioners/__init__.py +3 -6
  41. prefect/infrastructure/provisioners/coiled.py +3 -3
  42. prefect/infrastructure/provisioners/container_instance.py +1 -0
  43. prefect/infrastructure/provisioners/ecs.py +6 -6
  44. prefect/infrastructure/provisioners/modal.py +3 -3
  45. prefect/input/run_input.py +5 -7
  46. prefect/locking/filesystem.py +4 -3
  47. prefect/main.py +1 -1
  48. prefect/results.py +42 -249
  49. prefect/runner/runner.py +9 -4
  50. prefect/runner/server.py +5 -5
  51. prefect/runner/storage.py +12 -10
  52. prefect/runner/submit.py +2 -4
  53. prefect/schedules.py +231 -0
  54. prefect/serializers.py +5 -5
  55. prefect/settings/__init__.py +2 -1
  56. prefect/settings/base.py +3 -3
  57. prefect/settings/models/root.py +4 -0
  58. prefect/settings/models/server/services.py +50 -9
  59. prefect/settings/sources.py +4 -4
  60. prefect/states.py +42 -11
  61. prefect/task_engine.py +10 -10
  62. prefect/task_runners.py +11 -22
  63. prefect/task_worker.py +9 -9
  64. prefect/tasks.py +22 -41
  65. prefect/telemetry/bootstrap.py +4 -6
  66. prefect/telemetry/services.py +2 -4
  67. prefect/types/__init__.py +2 -1
  68. prefect/types/_datetime.py +28 -1
  69. prefect/utilities/_engine.py +0 -1
  70. prefect/utilities/asyncutils.py +4 -8
  71. prefect/utilities/collections.py +13 -22
  72. prefect/utilities/dispatch.py +2 -4
  73. prefect/utilities/dockerutils.py +6 -6
  74. prefect/utilities/importtools.py +1 -68
  75. prefect/utilities/names.py +1 -1
  76. prefect/utilities/processutils.py +3 -6
  77. prefect/utilities/pydantic.py +4 -6
  78. prefect/utilities/schema_tools/hydration.py +6 -5
  79. prefect/utilities/templating.py +16 -10
  80. prefect/utilities/visualization.py +2 -4
  81. prefect/workers/base.py +3 -3
  82. prefect/workers/block.py +1 -0
  83. prefect/workers/cloud.py +1 -0
  84. prefect/workers/process.py +1 -0
  85. {prefect_client-3.1.15.dist-info → prefect_client-3.2.0.dist-info}/METADATA +1 -1
  86. {prefect_client-3.1.15.dist-info → prefect_client-3.2.0.dist-info}/RECORD +89 -85
  87. {prefect_client-3.1.15.dist-info → prefect_client-3.2.0.dist-info}/LICENSE +0 -0
  88. {prefect_client-3.1.15.dist-info → prefect_client-3.2.0.dist-info}/WHEEL +0 -0
  89. {prefect_client-3.1.15.dist-info → prefect_client-3.2.0.dist-info}/top_level.txt +0 -0
prefect/automations.py CHANGED
@@ -179,13 +179,11 @@ class Automation(AutomationCore):
179
179
 
180
180
  @overload
181
181
  @classmethod
182
- async def aread(cls, id: UUID, name: Optional[str] = ...) -> Self:
183
- ...
182
+ async def aread(cls, id: UUID, name: Optional[str] = ...) -> Self: ...
184
183
 
185
184
  @overload
186
185
  @classmethod
187
- async def aread(cls, id: None = None, name: str = ...) -> Self:
188
- ...
186
+ async def aread(cls, id: None = None, name: str = ...) -> Self: ...
189
187
 
190
188
  @classmethod
191
189
  async def aread(cls, id: Optional[UUID] = None, name: Optional[str] = None) -> Self:
@@ -227,13 +225,11 @@ class Automation(AutomationCore):
227
225
 
228
226
  @overload
229
227
  @classmethod
230
- async def read(cls, id: UUID, name: Optional[str] = ...) -> Self:
231
- ...
228
+ async def read(cls, id: UUID, name: Optional[str] = ...) -> Self: ...
232
229
 
233
230
  @overload
234
231
  @classmethod
235
- async def read(cls, id: None = None, name: str = ...) -> Self:
236
- ...
232
+ async def read(cls, id: None = None, name: str = ...) -> Self: ...
237
233
 
238
234
  @classmethod
239
235
  @async_dispatch(aread)
@@ -22,14 +22,14 @@ class AbstractAppriseNotificationBlock(NotificationBlock, ABC):
22
22
  An abstract class for sending notifications using Apprise.
23
23
  """
24
24
 
25
- notify_type: Literal[
26
- "prefect_default", "info", "success", "warning", "failure"
27
- ] = Field(
28
- default=PREFECT_NOTIFY_TYPE_DEFAULT,
29
- description=(
30
- "The type of notification being performed; the prefect_default "
31
- "is a plain notification that does not attach an image."
32
- ),
25
+ notify_type: Literal["prefect_default", "info", "success", "warning", "failure"] = (
26
+ Field(
27
+ default=PREFECT_NOTIFY_TYPE_DEFAULT,
28
+ description=(
29
+ "The type of notification being performed; the prefect_default "
30
+ "is a plain notification that does not attach an image."
31
+ ),
32
+ )
33
33
  )
34
34
 
35
35
  def __init__(self, *args: Any, **kwargs: Any):
prefect/cache_policies.py CHANGED
@@ -252,6 +252,8 @@ class _None(CachePolicy):
252
252
  class TaskSource(CachePolicy):
253
253
  """
254
254
  Policy for computing a cache key based on the source code of the task.
255
+
256
+ This policy only considers raw lines of code in the task, and not the source code of nested tasks.
255
257
  """
256
258
 
257
259
  def compute_key(
prefect/client/base.py CHANGED
@@ -55,8 +55,7 @@ Send = Callable[[Message], Awaitable[None]]
55
55
 
56
56
  @runtime_checkable
57
57
  class ASGIApp(Protocol):
58
- async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
59
- ...
58
+ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: ...
60
59
 
61
60
 
62
61
  @asynccontextmanager
@@ -301,9 +300,9 @@ class PrefectHttpxAsyncClient(httpx.AsyncClient):
301
300
  )
302
301
  await anyio.sleep(retry_seconds)
303
302
 
304
- assert (
305
- response is not None
306
- ), "Retry handling ended without response or exception"
303
+ assert response is not None, (
304
+ "Retry handling ended without response or exception"
305
+ )
307
306
 
308
307
  # We ran out of retries, return the failed response
309
308
  return response
@@ -520,9 +519,9 @@ class PrefectHttpxSyncClient(httpx.Client):
520
519
  )
521
520
  time.sleep(retry_seconds)
522
521
 
523
- assert (
524
- response is not None
525
- ), "Retry handling ended without response or exception"
522
+ assert response is not None, (
523
+ "Retry handling ended without response or exception"
524
+ )
526
525
 
527
526
  # We ran out of retries, return the failed response
528
527
  return response
@@ -7,14 +7,11 @@ from prefect.client.orchestration import ServerType, get_client
7
7
 
8
8
 
9
9
  class CollectionsMetadataClient(Protocol):
10
- async def read_worker_metadata(self) -> Dict[str, Any]:
11
- ...
10
+ async def read_worker_metadata(self) -> Dict[str, Any]: ...
12
11
 
13
- async def __aenter__(self) -> "CollectionsMetadataClient":
14
- ...
12
+ async def __aenter__(self) -> "CollectionsMetadataClient": ...
15
13
 
16
- async def __aexit__(self, *exc_info: Any) -> Any:
17
- ...
14
+ async def __aexit__(self, *exc_info: Any) -> Any: ...
18
15
 
19
16
 
20
17
  def get_collections_metadata_client(
@@ -2,7 +2,6 @@ import asyncio
2
2
  import base64
3
3
  import datetime
4
4
  import ssl
5
- import warnings
6
5
  from collections.abc import Iterable
7
6
  from contextlib import AsyncExitStack
8
7
  from logging import Logger
@@ -48,6 +47,12 @@ from prefect.client.orchestration._automations.client import (
48
47
  AutomationClient,
49
48
  AutomationAsyncClient,
50
49
  )
50
+
51
+ from prefect.client.orchestration._work_pools.client import (
52
+ WorkPoolClient,
53
+ WorkPoolAsyncClient,
54
+ )
55
+
51
56
  from prefect._experimental.sla.client import SlaClient, SlaAsyncClient
52
57
 
53
58
  from prefect.client.orchestration._flows.client import (
@@ -85,8 +90,6 @@ from prefect.client.schemas.actions import (
85
90
  FlowRunNotificationPolicyUpdate,
86
91
  TaskRunCreate,
87
92
  TaskRunUpdate,
88
- WorkPoolCreate,
89
- WorkPoolUpdate,
90
93
  WorkQueueCreate,
91
94
  WorkQueueUpdate,
92
95
  )
@@ -96,8 +99,6 @@ from prefect.client.schemas.filters import (
96
99
  FlowRunFilter,
97
100
  FlowRunNotificationPolicyFilter,
98
101
  TaskRunFilter,
99
- WorkerFilter,
100
- WorkPoolFilter,
101
102
  WorkQueueFilter,
102
103
  WorkQueueFilterName,
103
104
  )
@@ -107,15 +108,10 @@ from prefect.client.schemas.objects import (
107
108
  Parameter,
108
109
  TaskRunPolicy,
109
110
  TaskRunResult,
110
- Worker,
111
- WorkerMetadata,
112
- WorkPool,
113
111
  WorkQueue,
114
112
  WorkQueueStatusDetail,
115
113
  )
116
- from prefect.client.schemas.responses import (
117
- WorkerFlowRunResponse,
118
- )
114
+
119
115
  from prefect.client.schemas.sorting import (
120
116
  TaskRunSort,
121
117
  )
@@ -133,7 +129,6 @@ from prefect.settings import (
133
129
  PREFECT_CLOUD_API_URL,
134
130
  PREFECT_SERVER_ALLOW_EPHEMERAL_MODE,
135
131
  PREFECT_TESTING_UNIT_TEST_MODE,
136
- get_current_settings,
137
132
  )
138
133
 
139
134
  if TYPE_CHECKING:
@@ -157,15 +152,13 @@ def get_client(
157
152
  *,
158
153
  httpx_settings: Optional[dict[str, Any]] = ...,
159
154
  sync_client: Literal[False] = False,
160
- ) -> "PrefectClient":
161
- ...
155
+ ) -> "PrefectClient": ...
162
156
 
163
157
 
164
158
  @overload
165
159
  def get_client(
166
160
  *, httpx_settings: Optional[dict[str, Any]] = ..., sync_client: Literal[True] = ...
167
- ) -> "SyncPrefectClient":
168
- ...
161
+ ) -> "SyncPrefectClient": ...
169
162
 
170
163
 
171
164
  def get_client(
@@ -263,6 +256,7 @@ class PrefectClient(
263
256
  BlocksDocumentAsyncClient,
264
257
  BlocksSchemaAsyncClient,
265
258
  BlocksTypeAsyncClient,
259
+ WorkPoolAsyncClient,
266
260
  ):
267
261
  """
268
262
  An asynchronous client for interacting with the [Prefect REST API](/api-ref/rest-api/).
@@ -814,7 +808,7 @@ class PrefectClient(
814
808
  retry_delay=retry_delay,
815
809
  retry_jitter_factor=task.retry_jitter_factor,
816
810
  ),
817
- state=state.to_state_create(),
811
+ state=prefect.states.to_state_create(state),
818
812
  task_inputs=task_inputs or {},
819
813
  )
820
814
  content = task_run_data.model_dump_json(exclude={"id"} if id is None else None)
@@ -925,7 +919,7 @@ class PrefectClient(
925
919
  Returns:
926
920
  an OrchestrationResult model representation of state orchestration output
927
921
  """
928
- state_create = state.to_state_create()
922
+ state_create = prefect.states.to_state_create(state)
929
923
  state_create.state_details.task_run_id = task_run_id
930
924
  response = await self._client.post(
931
925
  f"/task_runs/{task_run_id}/set_state",
@@ -1100,214 +1094,6 @@ class PrefectClient(
1100
1094
  response.json()
1101
1095
  )
1102
1096
 
1103
- async def send_worker_heartbeat(
1104
- self,
1105
- work_pool_name: str,
1106
- worker_name: str,
1107
- heartbeat_interval_seconds: Optional[float] = None,
1108
- get_worker_id: bool = False,
1109
- worker_metadata: Optional[WorkerMetadata] = None,
1110
- ) -> Optional[UUID]:
1111
- """
1112
- Sends a worker heartbeat for a given work pool.
1113
-
1114
- Args:
1115
- work_pool_name: The name of the work pool to heartbeat against.
1116
- worker_name: The name of the worker sending the heartbeat.
1117
- return_id: Whether to return the worker ID. Note: will return `None` if the connected server does not support returning worker IDs, even if `return_id` is `True`.
1118
- worker_metadata: Metadata about the worker to send to the server.
1119
- """
1120
- params: dict[str, Any] = {
1121
- "name": worker_name,
1122
- "heartbeat_interval_seconds": heartbeat_interval_seconds,
1123
- }
1124
- if worker_metadata:
1125
- params["metadata"] = worker_metadata.model_dump(mode="json")
1126
- if get_worker_id:
1127
- params["return_id"] = get_worker_id
1128
-
1129
- resp = await self._client.post(
1130
- f"/work_pools/{work_pool_name}/workers/heartbeat",
1131
- json=params,
1132
- )
1133
-
1134
- if (
1135
- (
1136
- self.server_type == ServerType.CLOUD
1137
- or get_current_settings().testing.test_mode
1138
- )
1139
- and get_worker_id
1140
- and resp.status_code == 200
1141
- ):
1142
- return UUID(resp.text)
1143
- else:
1144
- return None
1145
-
1146
- async def read_workers_for_work_pool(
1147
- self,
1148
- work_pool_name: str,
1149
- worker_filter: Optional[WorkerFilter] = None,
1150
- offset: Optional[int] = None,
1151
- limit: Optional[int] = None,
1152
- ) -> list[Worker]:
1153
- """
1154
- Reads workers for a given work pool.
1155
-
1156
- Args:
1157
- work_pool_name: The name of the work pool for which to get
1158
- member workers.
1159
- worker_filter: Criteria by which to filter workers.
1160
- limit: Limit for the worker query.
1161
- offset: Limit for the worker query.
1162
- """
1163
- response = await self._client.post(
1164
- f"/work_pools/{work_pool_name}/workers/filter",
1165
- json={
1166
- "workers": (
1167
- worker_filter.model_dump(mode="json", exclude_unset=True)
1168
- if worker_filter
1169
- else None
1170
- ),
1171
- "offset": offset,
1172
- "limit": limit,
1173
- },
1174
- )
1175
-
1176
- return pydantic.TypeAdapter(list[Worker]).validate_python(response.json())
1177
-
1178
- async def read_work_pool(self, work_pool_name: str) -> WorkPool:
1179
- """
1180
- Reads information for a given work pool
1181
-
1182
- Args:
1183
- work_pool_name: The name of the work pool to for which to get
1184
- information.
1185
-
1186
- Returns:
1187
- Information about the requested work pool.
1188
- """
1189
- try:
1190
- response = await self._client.get(f"/work_pools/{work_pool_name}")
1191
- return WorkPool.model_validate(response.json())
1192
- except httpx.HTTPStatusError as e:
1193
- if e.response.status_code == status.HTTP_404_NOT_FOUND:
1194
- raise prefect.exceptions.ObjectNotFound(http_exc=e) from e
1195
- else:
1196
- raise
1197
-
1198
- async def read_work_pools(
1199
- self,
1200
- limit: Optional[int] = None,
1201
- offset: int = 0,
1202
- work_pool_filter: Optional[WorkPoolFilter] = None,
1203
- ) -> list[WorkPool]:
1204
- """
1205
- Reads work pools.
1206
-
1207
- Args:
1208
- limit: Limit for the work pool query.
1209
- offset: Offset for the work pool query.
1210
- work_pool_filter: Criteria by which to filter work pools.
1211
-
1212
- Returns:
1213
- A list of work pools.
1214
- """
1215
-
1216
- body: dict[str, Any] = {
1217
- "limit": limit,
1218
- "offset": offset,
1219
- "work_pools": (
1220
- work_pool_filter.model_dump(mode="json") if work_pool_filter else None
1221
- ),
1222
- }
1223
- response = await self._client.post("/work_pools/filter", json=body)
1224
- return pydantic.TypeAdapter(list[WorkPool]).validate_python(response.json())
1225
-
1226
- async def create_work_pool(
1227
- self,
1228
- work_pool: WorkPoolCreate,
1229
- overwrite: bool = False,
1230
- ) -> WorkPool:
1231
- """
1232
- Creates a work pool with the provided configuration.
1233
-
1234
- Args:
1235
- work_pool: Desired configuration for the new work pool.
1236
-
1237
- Returns:
1238
- Information about the newly created work pool.
1239
- """
1240
- try:
1241
- response = await self._client.post(
1242
- "/work_pools/",
1243
- json=work_pool.model_dump(mode="json", exclude_unset=True),
1244
- )
1245
- except httpx.HTTPStatusError as e:
1246
- if e.response.status_code == status.HTTP_409_CONFLICT:
1247
- if overwrite:
1248
- existing_work_pool = await self.read_work_pool(
1249
- work_pool_name=work_pool.name
1250
- )
1251
- if existing_work_pool.type != work_pool.type:
1252
- warnings.warn(
1253
- "Overwriting work pool type is not supported. Ignoring provided type.",
1254
- category=UserWarning,
1255
- )
1256
- await self.update_work_pool(
1257
- work_pool_name=work_pool.name,
1258
- work_pool=WorkPoolUpdate.model_validate(
1259
- work_pool.model_dump(exclude={"name", "type"})
1260
- ),
1261
- )
1262
- response = await self._client.get(f"/work_pools/{work_pool.name}")
1263
- else:
1264
- raise prefect.exceptions.ObjectAlreadyExists(http_exc=e) from e
1265
- else:
1266
- raise
1267
-
1268
- return WorkPool.model_validate(response.json())
1269
-
1270
- async def update_work_pool(
1271
- self,
1272
- work_pool_name: str,
1273
- work_pool: WorkPoolUpdate,
1274
- ) -> None:
1275
- """
1276
- Updates a work pool.
1277
-
1278
- Args:
1279
- work_pool_name: Name of the work pool to update.
1280
- work_pool: Fields to update in the work pool.
1281
- """
1282
- try:
1283
- await self._client.patch(
1284
- f"/work_pools/{work_pool_name}",
1285
- json=work_pool.model_dump(mode="json", exclude_unset=True),
1286
- )
1287
- except httpx.HTTPStatusError as e:
1288
- if e.response.status_code == status.HTTP_404_NOT_FOUND:
1289
- raise prefect.exceptions.ObjectNotFound(http_exc=e) from e
1290
- else:
1291
- raise
1292
-
1293
- async def delete_work_pool(
1294
- self,
1295
- work_pool_name: str,
1296
- ) -> None:
1297
- """
1298
- Deletes a work pool.
1299
-
1300
- Args:
1301
- work_pool_name: Name of the work pool to delete.
1302
- """
1303
- try:
1304
- await self._client.delete(f"/work_pools/{work_pool_name}")
1305
- except httpx.HTTPStatusError as e:
1306
- if e.response.status_code == status.HTTP_404_NOT_FOUND:
1307
- raise prefect.exceptions.ObjectNotFound(http_exc=e) from e
1308
- else:
1309
- raise
1310
-
1311
1097
  async def read_work_queues(
1312
1098
  self,
1313
1099
  work_pool_name: Optional[str] = None,
@@ -1353,41 +1139,6 @@ class PrefectClient(
1353
1139
 
1354
1140
  return pydantic.TypeAdapter(list[WorkQueue]).validate_python(response.json())
1355
1141
 
1356
- async def get_scheduled_flow_runs_for_work_pool(
1357
- self,
1358
- work_pool_name: str,
1359
- work_queue_names: Optional[list[str]] = None,
1360
- scheduled_before: Optional[datetime.datetime] = None,
1361
- ) -> list[WorkerFlowRunResponse]:
1362
- """
1363
- Retrieves scheduled flow runs for the provided set of work pool queues.
1364
-
1365
- Args:
1366
- work_pool_name: The name of the work pool that the work pool
1367
- queues are associated with.
1368
- work_queue_names: The names of the work pool queues from which
1369
- to get scheduled flow runs.
1370
- scheduled_before: Datetime used to filter returned flow runs. Flow runs
1371
- scheduled for after the given datetime string will not be returned.
1372
-
1373
- Returns:
1374
- A list of worker flow run responses containing information about the
1375
- retrieved flow runs.
1376
- """
1377
- body: dict[str, Any] = {}
1378
- if work_queue_names is not None:
1379
- body["work_queue_names"] = list(work_queue_names)
1380
- if scheduled_before:
1381
- body["scheduled_before"] = str(scheduled_before)
1382
-
1383
- response = await self._client.post(
1384
- f"/work_pools/{work_pool_name}/get_scheduled_flow_runs",
1385
- json=body,
1386
- )
1387
- return pydantic.TypeAdapter(list[WorkerFlowRunResponse]).validate_python(
1388
- response.json()
1389
- )
1390
-
1391
1142
  async def read_worker_metadata(self) -> dict[str, Any]:
1392
1143
  """Reads worker metadata stored in Prefect collection registry."""
1393
1144
  response = await self._client.get("collections/views/aggregate-worker-metadata")
@@ -1504,6 +1255,7 @@ class SyncPrefectClient(
1504
1255
  BlocksDocumentClient,
1505
1256
  BlocksSchemaClient,
1506
1257
  BlocksTypeClient,
1258
+ WorkPoolClient,
1507
1259
  ):
1508
1260
  """
1509
1261
  A synchronous client for interacting with the [Prefect REST API](/api-ref/rest-api/).
@@ -1834,7 +1586,7 @@ class SyncPrefectClient(
1834
1586
  retry_delay=retry_delay,
1835
1587
  retry_jitter_factor=task.retry_jitter_factor,
1836
1588
  ),
1837
- state=state.to_state_create(),
1589
+ state=prefect.states.to_state_create(state),
1838
1590
  task_inputs=task_inputs or {},
1839
1591
  )
1840
1592
 
@@ -1928,7 +1680,7 @@ class SyncPrefectClient(
1928
1680
  Returns:
1929
1681
  an OrchestrationResult model representation of state orchestration output
1930
1682
  """
1931
- state_create = state.to_state_create()
1683
+ state_create = prefect.states.to_state_create(state)
1932
1684
  state_create.state_details.task_run_id = task_run_id
1933
1685
  response = self._client.post(
1934
1686
  f"/task_runs/{task_run_id}/set_state",
@@ -165,7 +165,11 @@ class DeploymentClient(BaseClient):
165
165
  "PATCH",
166
166
  "/deployments/{id}",
167
167
  path_params={"id": deployment_id},
168
- json=deployment.model_dump(mode="json", exclude_unset=True),
168
+ json=deployment.model_dump(
169
+ mode="json",
170
+ exclude_unset=True,
171
+ exclude={"name", "flow_name", "triggers"},
172
+ ),
169
173
  )
170
174
 
171
175
  def _create_deployment_from_schema(self, schema: "DeploymentCreate") -> "UUID":
@@ -550,7 +554,7 @@ class DeploymentClient(BaseClient):
550
554
  """
551
555
  from prefect.client.schemas.actions import DeploymentFlowRunCreate
552
556
  from prefect.client.schemas.objects import FlowRun
553
- from prefect.states import Scheduled
557
+ from prefect.states import Scheduled, to_state_create
554
558
 
555
559
  parameters = parameters or {}
556
560
  context = context or {}
@@ -561,7 +565,7 @@ class DeploymentClient(BaseClient):
561
565
  flow_run_create = DeploymentFlowRunCreate(
562
566
  parameters=parameters,
563
567
  context=context,
564
- state=state.to_state_create(),
568
+ state=to_state_create(state),
565
569
  tags=list(tags),
566
570
  name=name,
567
571
  idempotency_key=idempotency_key,
@@ -708,7 +712,11 @@ class DeploymentAsyncClient(BaseAsyncClient):
708
712
  "PATCH",
709
713
  "/deployments/{id}",
710
714
  path_params={"id": deployment_id},
711
- json=deployment.model_dump(mode="json", exclude_unset=True),
715
+ json=deployment.model_dump(
716
+ mode="json",
717
+ exclude_unset=True,
718
+ exclude={"name", "flow_name", "triggers"},
719
+ ),
712
720
  )
713
721
 
714
722
  async def _create_deployment_from_schema(
@@ -1095,7 +1103,7 @@ class DeploymentAsyncClient(BaseAsyncClient):
1095
1103
  """
1096
1104
  from prefect.client.schemas.actions import DeploymentFlowRunCreate
1097
1105
  from prefect.client.schemas.objects import FlowRun
1098
- from prefect.states import Scheduled
1106
+ from prefect.states import Scheduled, to_state_create
1099
1107
 
1100
1108
  parameters = parameters or {}
1101
1109
  context = context or {}
@@ -1106,7 +1114,7 @@ class DeploymentAsyncClient(BaseAsyncClient):
1106
1114
  flow_run_create = DeploymentFlowRunCreate(
1107
1115
  parameters=parameters,
1108
1116
  context=context,
1109
- state=state.to_state_create(),
1117
+ state=to_state_create(state),
1110
1118
  tags=list(tags),
1111
1119
  name=name,
1112
1120
  idempotency_key=idempotency_key,
@@ -69,7 +69,7 @@ class FlowRunClient(BaseClient):
69
69
  """
70
70
  from prefect.client.schemas.actions import FlowCreate, FlowRunCreate
71
71
  from prefect.client.schemas.objects import Flow, FlowRun, FlowRunPolicy
72
- from prefect.states import Pending
72
+ from prefect.states import Pending, to_state_create
73
73
 
74
74
  parameters = parameters or {}
75
75
  context = context or {}
@@ -93,7 +93,7 @@ class FlowRunClient(BaseClient):
93
93
  context=context,
94
94
  tags=list(tags or []),
95
95
  parent_task_run_id=parent_task_run_id,
96
- state=state.to_state_create(),
96
+ state=to_state_create(state),
97
97
  empirical_policy=FlowRunPolicy(
98
98
  retries=flow.retries,
99
99
  retry_delay=int(flow.retry_delay_seconds or 0),
@@ -322,10 +322,12 @@ class FlowRunClient(BaseClient):
322
322
  """
323
323
  from uuid import UUID, uuid4
324
324
 
325
+ from prefect.states import to_state_create
326
+
325
327
  flow_run_id = (
326
328
  flow_run_id if isinstance(flow_run_id, UUID) else UUID(flow_run_id)
327
329
  )
328
- state_create = state.to_state_create()
330
+ state_create = to_state_create(state)
329
331
  state_create.state_details.flow_run_id = flow_run_id
330
332
  state_create.state_details.transition_id = uuid4()
331
333
  try:
@@ -501,7 +503,7 @@ class FlowRunAsyncClient(BaseAsyncClient):
501
503
  """
502
504
  from prefect.client.schemas.actions import FlowCreate, FlowRunCreate
503
505
  from prefect.client.schemas.objects import Flow, FlowRun, FlowRunPolicy
504
- from prefect.states import Pending
506
+ from prefect.states import Pending, to_state_create
505
507
 
506
508
  parameters = parameters or {}
507
509
  context = context or {}
@@ -525,7 +527,7 @@ class FlowRunAsyncClient(BaseAsyncClient):
525
527
  context=context,
526
528
  tags=list(tags or []),
527
529
  parent_task_run_id=parent_task_run_id,
528
- state=state.to_state_create(),
530
+ state=to_state_create(state),
529
531
  empirical_policy=FlowRunPolicy(
530
532
  retries=flow.retries,
531
533
  retry_delay=int(flow.retry_delay_seconds or 0),
@@ -755,10 +757,12 @@ class FlowRunAsyncClient(BaseAsyncClient):
755
757
  """
756
758
  from uuid import UUID, uuid4
757
759
 
760
+ from prefect.states import to_state_create
761
+
758
762
  flow_run_id = (
759
763
  flow_run_id if isinstance(flow_run_id, UUID) else UUID(flow_run_id)
760
764
  )
761
- state_create = state.to_state_create()
765
+ state_create = to_state_create(state)
762
766
  state_create.state_details.flow_run_id = flow_run_id
763
767
  state_create.state_details.transition_id = uuid4()
764
768
  try:
File without changes