prefect-client 2.20.2__py3-none-any.whl → 3.0.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 (288) hide show
  1. prefect/__init__.py +74 -110
  2. prefect/_internal/compatibility/deprecated.py +6 -115
  3. prefect/_internal/compatibility/experimental.py +4 -79
  4. prefect/_internal/compatibility/migration.py +166 -0
  5. prefect/_internal/concurrency/__init__.py +2 -2
  6. prefect/_internal/concurrency/api.py +1 -35
  7. prefect/_internal/concurrency/calls.py +0 -6
  8. prefect/_internal/concurrency/cancellation.py +0 -3
  9. prefect/_internal/concurrency/event_loop.py +0 -20
  10. prefect/_internal/concurrency/inspection.py +3 -3
  11. prefect/_internal/concurrency/primitives.py +1 -0
  12. prefect/_internal/concurrency/services.py +23 -0
  13. prefect/_internal/concurrency/threads.py +35 -0
  14. prefect/_internal/concurrency/waiters.py +0 -28
  15. prefect/_internal/integrations.py +7 -0
  16. prefect/_internal/pydantic/__init__.py +0 -45
  17. prefect/_internal/pydantic/annotations/pendulum.py +2 -2
  18. prefect/_internal/pydantic/v1_schema.py +21 -22
  19. prefect/_internal/pydantic/v2_schema.py +0 -2
  20. prefect/_internal/pydantic/v2_validated_func.py +18 -23
  21. prefect/_internal/pytz.py +1 -1
  22. prefect/_internal/retries.py +61 -0
  23. prefect/_internal/schemas/bases.py +45 -177
  24. prefect/_internal/schemas/fields.py +1 -43
  25. prefect/_internal/schemas/validators.py +47 -233
  26. prefect/agent.py +3 -695
  27. prefect/artifacts.py +173 -14
  28. prefect/automations.py +39 -4
  29. prefect/blocks/abstract.py +1 -1
  30. prefect/blocks/core.py +423 -164
  31. prefect/blocks/fields.py +2 -57
  32. prefect/blocks/notifications.py +43 -28
  33. prefect/blocks/redis.py +168 -0
  34. prefect/blocks/system.py +67 -20
  35. prefect/blocks/webhook.py +2 -9
  36. prefect/cache_policies.py +239 -0
  37. prefect/client/__init__.py +4 -0
  38. prefect/client/base.py +33 -27
  39. prefect/client/cloud.py +65 -20
  40. prefect/client/collections.py +1 -1
  41. prefect/client/orchestration.py +667 -440
  42. prefect/client/schemas/actions.py +115 -100
  43. prefect/client/schemas/filters.py +46 -52
  44. prefect/client/schemas/objects.py +228 -178
  45. prefect/client/schemas/responses.py +18 -36
  46. prefect/client/schemas/schedules.py +55 -36
  47. prefect/client/schemas/sorting.py +2 -0
  48. prefect/client/subscriptions.py +8 -7
  49. prefect/client/types/flexible_schedule_list.py +11 -0
  50. prefect/client/utilities.py +9 -6
  51. prefect/concurrency/asyncio.py +60 -11
  52. prefect/concurrency/context.py +24 -0
  53. prefect/concurrency/events.py +2 -2
  54. prefect/concurrency/services.py +46 -16
  55. prefect/concurrency/sync.py +51 -7
  56. prefect/concurrency/v1/asyncio.py +143 -0
  57. prefect/concurrency/v1/context.py +27 -0
  58. prefect/concurrency/v1/events.py +61 -0
  59. prefect/concurrency/v1/services.py +116 -0
  60. prefect/concurrency/v1/sync.py +92 -0
  61. prefect/context.py +246 -149
  62. prefect/deployments/__init__.py +33 -18
  63. prefect/deployments/base.py +10 -15
  64. prefect/deployments/deployments.py +2 -1048
  65. prefect/deployments/flow_runs.py +178 -0
  66. prefect/deployments/runner.py +72 -173
  67. prefect/deployments/schedules.py +31 -25
  68. prefect/deployments/steps/__init__.py +0 -1
  69. prefect/deployments/steps/core.py +7 -0
  70. prefect/deployments/steps/pull.py +15 -21
  71. prefect/deployments/steps/utility.py +2 -1
  72. prefect/docker/__init__.py +20 -0
  73. prefect/docker/docker_image.py +82 -0
  74. prefect/engine.py +15 -2466
  75. prefect/events/actions.py +17 -23
  76. prefect/events/cli/automations.py +20 -7
  77. prefect/events/clients.py +142 -80
  78. prefect/events/filters.py +14 -18
  79. prefect/events/related.py +74 -75
  80. prefect/events/schemas/__init__.py +0 -5
  81. prefect/events/schemas/automations.py +55 -46
  82. prefect/events/schemas/deployment_triggers.py +7 -197
  83. prefect/events/schemas/events.py +46 -65
  84. prefect/events/schemas/labelling.py +10 -14
  85. prefect/events/utilities.py +4 -5
  86. prefect/events/worker.py +23 -8
  87. prefect/exceptions.py +15 -0
  88. prefect/filesystems.py +30 -529
  89. prefect/flow_engine.py +827 -0
  90. prefect/flow_runs.py +379 -7
  91. prefect/flows.py +470 -360
  92. prefect/futures.py +382 -331
  93. prefect/infrastructure/__init__.py +5 -26
  94. prefect/infrastructure/base.py +3 -320
  95. prefect/infrastructure/provisioners/__init__.py +5 -3
  96. prefect/infrastructure/provisioners/cloud_run.py +13 -8
  97. prefect/infrastructure/provisioners/container_instance.py +14 -9
  98. prefect/infrastructure/provisioners/ecs.py +10 -8
  99. prefect/infrastructure/provisioners/modal.py +8 -5
  100. prefect/input/__init__.py +4 -0
  101. prefect/input/actions.py +2 -4
  102. prefect/input/run_input.py +9 -9
  103. prefect/logging/formatters.py +2 -4
  104. prefect/logging/handlers.py +9 -14
  105. prefect/logging/loggers.py +5 -5
  106. prefect/main.py +72 -0
  107. prefect/plugins.py +2 -64
  108. prefect/profiles.toml +16 -2
  109. prefect/records/__init__.py +1 -0
  110. prefect/records/base.py +223 -0
  111. prefect/records/filesystem.py +207 -0
  112. prefect/records/memory.py +178 -0
  113. prefect/records/result_store.py +64 -0
  114. prefect/results.py +577 -504
  115. prefect/runner/runner.py +124 -51
  116. prefect/runner/server.py +32 -34
  117. prefect/runner/storage.py +3 -12
  118. prefect/runner/submit.py +2 -10
  119. prefect/runner/utils.py +2 -2
  120. prefect/runtime/__init__.py +1 -0
  121. prefect/runtime/deployment.py +1 -0
  122. prefect/runtime/flow_run.py +40 -5
  123. prefect/runtime/task_run.py +1 -0
  124. prefect/serializers.py +28 -39
  125. prefect/server/api/collections_data/views/aggregate-worker-metadata.json +5 -14
  126. prefect/settings.py +209 -332
  127. prefect/states.py +160 -63
  128. prefect/task_engine.py +1478 -57
  129. prefect/task_runners.py +383 -287
  130. prefect/task_runs.py +240 -0
  131. prefect/task_worker.py +463 -0
  132. prefect/tasks.py +684 -374
  133. prefect/transactions.py +410 -0
  134. prefect/types/__init__.py +72 -86
  135. prefect/types/entrypoint.py +13 -0
  136. prefect/utilities/annotations.py +4 -3
  137. prefect/utilities/asyncutils.py +227 -148
  138. prefect/utilities/callables.py +138 -48
  139. prefect/utilities/collections.py +134 -86
  140. prefect/utilities/dispatch.py +27 -14
  141. prefect/utilities/dockerutils.py +11 -4
  142. prefect/utilities/engine.py +186 -32
  143. prefect/utilities/filesystem.py +4 -5
  144. prefect/utilities/importtools.py +26 -27
  145. prefect/utilities/pydantic.py +128 -38
  146. prefect/utilities/schema_tools/hydration.py +18 -1
  147. prefect/utilities/schema_tools/validation.py +30 -0
  148. prefect/utilities/services.py +35 -9
  149. prefect/utilities/templating.py +12 -2
  150. prefect/utilities/timeout.py +20 -5
  151. prefect/utilities/urls.py +195 -0
  152. prefect/utilities/visualization.py +1 -0
  153. prefect/variables.py +78 -59
  154. prefect/workers/__init__.py +0 -1
  155. prefect/workers/base.py +237 -244
  156. prefect/workers/block.py +5 -226
  157. prefect/workers/cloud.py +6 -0
  158. prefect/workers/process.py +265 -12
  159. prefect/workers/server.py +29 -11
  160. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/METADATA +30 -26
  161. prefect_client-3.0.0.dist-info/RECORD +201 -0
  162. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/WHEEL +1 -1
  163. prefect/_internal/pydantic/_base_model.py +0 -51
  164. prefect/_internal/pydantic/_compat.py +0 -82
  165. prefect/_internal/pydantic/_flags.py +0 -20
  166. prefect/_internal/pydantic/_types.py +0 -8
  167. prefect/_internal/pydantic/utilities/config_dict.py +0 -72
  168. prefect/_internal/pydantic/utilities/field_validator.py +0 -150
  169. prefect/_internal/pydantic/utilities/model_construct.py +0 -56
  170. prefect/_internal/pydantic/utilities/model_copy.py +0 -55
  171. prefect/_internal/pydantic/utilities/model_dump.py +0 -136
  172. prefect/_internal/pydantic/utilities/model_dump_json.py +0 -112
  173. prefect/_internal/pydantic/utilities/model_fields.py +0 -50
  174. prefect/_internal/pydantic/utilities/model_fields_set.py +0 -29
  175. prefect/_internal/pydantic/utilities/model_json_schema.py +0 -82
  176. prefect/_internal/pydantic/utilities/model_rebuild.py +0 -80
  177. prefect/_internal/pydantic/utilities/model_validate.py +0 -75
  178. prefect/_internal/pydantic/utilities/model_validate_json.py +0 -68
  179. prefect/_internal/pydantic/utilities/model_validator.py +0 -87
  180. prefect/_internal/pydantic/utilities/type_adapter.py +0 -71
  181. prefect/_vendor/fastapi/__init__.py +0 -25
  182. prefect/_vendor/fastapi/applications.py +0 -946
  183. prefect/_vendor/fastapi/background.py +0 -3
  184. prefect/_vendor/fastapi/concurrency.py +0 -44
  185. prefect/_vendor/fastapi/datastructures.py +0 -58
  186. prefect/_vendor/fastapi/dependencies/__init__.py +0 -0
  187. prefect/_vendor/fastapi/dependencies/models.py +0 -64
  188. prefect/_vendor/fastapi/dependencies/utils.py +0 -877
  189. prefect/_vendor/fastapi/encoders.py +0 -177
  190. prefect/_vendor/fastapi/exception_handlers.py +0 -40
  191. prefect/_vendor/fastapi/exceptions.py +0 -46
  192. prefect/_vendor/fastapi/logger.py +0 -3
  193. prefect/_vendor/fastapi/middleware/__init__.py +0 -1
  194. prefect/_vendor/fastapi/middleware/asyncexitstack.py +0 -25
  195. prefect/_vendor/fastapi/middleware/cors.py +0 -3
  196. prefect/_vendor/fastapi/middleware/gzip.py +0 -3
  197. prefect/_vendor/fastapi/middleware/httpsredirect.py +0 -3
  198. prefect/_vendor/fastapi/middleware/trustedhost.py +0 -3
  199. prefect/_vendor/fastapi/middleware/wsgi.py +0 -3
  200. prefect/_vendor/fastapi/openapi/__init__.py +0 -0
  201. prefect/_vendor/fastapi/openapi/constants.py +0 -2
  202. prefect/_vendor/fastapi/openapi/docs.py +0 -203
  203. prefect/_vendor/fastapi/openapi/models.py +0 -480
  204. prefect/_vendor/fastapi/openapi/utils.py +0 -485
  205. prefect/_vendor/fastapi/param_functions.py +0 -340
  206. prefect/_vendor/fastapi/params.py +0 -453
  207. prefect/_vendor/fastapi/py.typed +0 -0
  208. prefect/_vendor/fastapi/requests.py +0 -4
  209. prefect/_vendor/fastapi/responses.py +0 -40
  210. prefect/_vendor/fastapi/routing.py +0 -1331
  211. prefect/_vendor/fastapi/security/__init__.py +0 -15
  212. prefect/_vendor/fastapi/security/api_key.py +0 -98
  213. prefect/_vendor/fastapi/security/base.py +0 -6
  214. prefect/_vendor/fastapi/security/http.py +0 -172
  215. prefect/_vendor/fastapi/security/oauth2.py +0 -227
  216. prefect/_vendor/fastapi/security/open_id_connect_url.py +0 -34
  217. prefect/_vendor/fastapi/security/utils.py +0 -10
  218. prefect/_vendor/fastapi/staticfiles.py +0 -1
  219. prefect/_vendor/fastapi/templating.py +0 -3
  220. prefect/_vendor/fastapi/testclient.py +0 -1
  221. prefect/_vendor/fastapi/types.py +0 -3
  222. prefect/_vendor/fastapi/utils.py +0 -235
  223. prefect/_vendor/fastapi/websockets.py +0 -7
  224. prefect/_vendor/starlette/__init__.py +0 -1
  225. prefect/_vendor/starlette/_compat.py +0 -28
  226. prefect/_vendor/starlette/_exception_handler.py +0 -80
  227. prefect/_vendor/starlette/_utils.py +0 -88
  228. prefect/_vendor/starlette/applications.py +0 -261
  229. prefect/_vendor/starlette/authentication.py +0 -159
  230. prefect/_vendor/starlette/background.py +0 -43
  231. prefect/_vendor/starlette/concurrency.py +0 -59
  232. prefect/_vendor/starlette/config.py +0 -151
  233. prefect/_vendor/starlette/convertors.py +0 -87
  234. prefect/_vendor/starlette/datastructures.py +0 -707
  235. prefect/_vendor/starlette/endpoints.py +0 -130
  236. prefect/_vendor/starlette/exceptions.py +0 -60
  237. prefect/_vendor/starlette/formparsers.py +0 -276
  238. prefect/_vendor/starlette/middleware/__init__.py +0 -17
  239. prefect/_vendor/starlette/middleware/authentication.py +0 -52
  240. prefect/_vendor/starlette/middleware/base.py +0 -220
  241. prefect/_vendor/starlette/middleware/cors.py +0 -176
  242. prefect/_vendor/starlette/middleware/errors.py +0 -265
  243. prefect/_vendor/starlette/middleware/exceptions.py +0 -74
  244. prefect/_vendor/starlette/middleware/gzip.py +0 -113
  245. prefect/_vendor/starlette/middleware/httpsredirect.py +0 -19
  246. prefect/_vendor/starlette/middleware/sessions.py +0 -82
  247. prefect/_vendor/starlette/middleware/trustedhost.py +0 -64
  248. prefect/_vendor/starlette/middleware/wsgi.py +0 -147
  249. prefect/_vendor/starlette/py.typed +0 -0
  250. prefect/_vendor/starlette/requests.py +0 -328
  251. prefect/_vendor/starlette/responses.py +0 -347
  252. prefect/_vendor/starlette/routing.py +0 -933
  253. prefect/_vendor/starlette/schemas.py +0 -154
  254. prefect/_vendor/starlette/staticfiles.py +0 -248
  255. prefect/_vendor/starlette/status.py +0 -199
  256. prefect/_vendor/starlette/templating.py +0 -231
  257. prefect/_vendor/starlette/testclient.py +0 -804
  258. prefect/_vendor/starlette/types.py +0 -30
  259. prefect/_vendor/starlette/websockets.py +0 -193
  260. prefect/blocks/kubernetes.py +0 -119
  261. prefect/deprecated/__init__.py +0 -0
  262. prefect/deprecated/data_documents.py +0 -350
  263. prefect/deprecated/packaging/__init__.py +0 -12
  264. prefect/deprecated/packaging/base.py +0 -96
  265. prefect/deprecated/packaging/docker.py +0 -146
  266. prefect/deprecated/packaging/file.py +0 -92
  267. prefect/deprecated/packaging/orion.py +0 -80
  268. prefect/deprecated/packaging/serializers.py +0 -171
  269. prefect/events/instrument.py +0 -135
  270. prefect/infrastructure/container.py +0 -824
  271. prefect/infrastructure/kubernetes.py +0 -920
  272. prefect/infrastructure/process.py +0 -289
  273. prefect/manifests.py +0 -20
  274. prefect/new_flow_engine.py +0 -449
  275. prefect/new_task_engine.py +0 -423
  276. prefect/pydantic/__init__.py +0 -76
  277. prefect/pydantic/main.py +0 -39
  278. prefect/software/__init__.py +0 -2
  279. prefect/software/base.py +0 -50
  280. prefect/software/conda.py +0 -199
  281. prefect/software/pip.py +0 -122
  282. prefect/software/python.py +0 -52
  283. prefect/task_server.py +0 -322
  284. prefect_client-2.20.2.dist-info/RECORD +0 -294
  285. /prefect/{_internal/pydantic/utilities → client/types}/__init__.py +0 -0
  286. /prefect/{_vendor → concurrency/v1}/__init__.py +0 -0
  287. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/LICENSE +0 -0
  288. {prefect_client-2.20.2.dist-info → prefect_client-3.0.0.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,6 @@
1
1
  import datetime
2
+ import warnings
3
+ from functools import partial
2
4
  from typing import (
3
5
  TYPE_CHECKING,
4
6
  Any,
@@ -6,38 +8,36 @@ from typing import (
6
8
  Generic,
7
9
  List,
8
10
  Optional,
9
- TypeVar,
10
11
  Union,
11
12
  overload,
12
13
  )
13
- from uuid import UUID
14
+ from uuid import UUID, uuid4
14
15
 
15
16
  import orjson
16
17
  import pendulum
17
-
18
- from prefect._internal.compatibility.deprecated import (
19
- DeprecatedInfraOverridesField,
20
- deprecated_class,
18
+ from pydantic import (
19
+ ConfigDict,
20
+ Field,
21
+ HttpUrl,
22
+ IPvAnyNetwork,
23
+ SerializationInfo,
24
+ field_validator,
25
+ model_serializer,
26
+ model_validator,
21
27
  )
22
- from prefect._internal.pydantic import HAS_PYDANTIC_V2
23
- from prefect.types import NonNegativeInteger, PositiveInteger
24
-
25
- if HAS_PYDANTIC_V2:
26
- from pydantic.v1 import Field, HttpUrl, root_validator, validator
27
- else:
28
- from pydantic import Field, HttpUrl, root_validator, validator
29
-
30
- from typing_extensions import Literal
28
+ from pydantic.functional_validators import ModelWrapValidatorHandler
29
+ from pydantic_extra_types.pendulum_dt import DateTime
30
+ from typing_extensions import Literal, Self, TypeVar
31
31
 
32
+ from prefect._internal.compatibility.migration import getattr_migration
32
33
  from prefect._internal.schemas.bases import ObjectBaseModel, PrefectBaseModel
33
- from prefect._internal.schemas.fields import CreatedBy, DateTimeTZ, UpdatedBy
34
+ from prefect._internal.schemas.fields import CreatedBy, UpdatedBy
34
35
  from prefect._internal.schemas.validators import (
35
36
  get_or_create_run_name,
36
- get_or_create_state_name,
37
37
  list_length_50_or_less,
38
38
  raise_on_name_alphanumeric_dashes_only,
39
- raise_on_name_with_banned_characters,
40
39
  set_run_policy_deprecated_fields,
40
+ validate_block_document_name,
41
41
  validate_default_queue_id_not_none,
42
42
  validate_max_metadata_length,
43
43
  validate_message_template_variables,
@@ -47,15 +47,22 @@ from prefect._internal.schemas.validators import (
47
47
  )
48
48
  from prefect.client.schemas.schedules import SCHEDULE_TYPES
49
49
  from prefect.settings import PREFECT_CLOUD_API_URL, PREFECT_CLOUD_UI_URL
50
- from prefect.utilities.collections import AutoEnum, listrepr
50
+ from prefect.types import (
51
+ MAX_VARIABLE_NAME_LENGTH,
52
+ Name,
53
+ NonNegativeInteger,
54
+ PositiveInteger,
55
+ StrictVariableValue,
56
+ )
57
+ from prefect.utilities.collections import AutoEnum, listrepr, visit_collection
51
58
  from prefect.utilities.names import generate_slug
59
+ from prefect.utilities.pydantic import handle_secret_render
52
60
 
53
61
  if TYPE_CHECKING:
54
- from prefect.deprecated.data_documents import DataDocument
55
62
  from prefect.results import BaseResult
56
63
 
57
64
 
58
- R = TypeVar("R")
65
+ R = TypeVar("R", default=Any)
59
66
 
60
67
 
61
68
  DEFAULT_BLOCK_SCHEMA_VERSION = "non-versioned"
@@ -73,8 +80,6 @@ FLOW_RUN_NOTIFICATION_TEMPLATE_KWARGS = [
73
80
  "flow_run_state_timestamp",
74
81
  "flow_run_state_message",
75
82
  ]
76
- MAX_VARIABLE_NAME_LENGTH = 255
77
- MAX_VARIABLE_VALUE_LENGTH = 5000
78
83
 
79
84
 
80
85
  class StateType(AutoEnum):
@@ -91,6 +96,14 @@ class StateType(AutoEnum):
91
96
  CANCELLING = AutoEnum.auto()
92
97
 
93
98
 
99
+ TERMINAL_STATES = {
100
+ StateType.COMPLETED,
101
+ StateType.CANCELLED,
102
+ StateType.FAILED,
103
+ StateType.CRASHED,
104
+ }
105
+
106
+
94
107
  class WorkPoolStatus(AutoEnum):
95
108
  """Enumeration of work pool statuses."""
96
109
 
@@ -130,11 +143,12 @@ class StateDetails(PrefectBaseModel):
130
143
  task_run_id: Optional[UUID] = None
131
144
  # for task runs that represent subflows, the subflow's run ID
132
145
  child_flow_run_id: Optional[UUID] = None
133
- scheduled_time: DateTimeTZ = None
146
+ scheduled_time: Optional[DateTime] = None
134
147
  cache_key: Optional[str] = None
135
- cache_expiration: DateTimeTZ = None
148
+ cache_expiration: Optional[DateTime] = None
149
+ deferred: Optional[bool] = None
136
150
  untrackable_result: bool = False
137
- pause_timeout: DateTimeTZ = None
151
+ pause_timeout: Optional[DateTime] = None
138
152
  pause_reschedule: bool = False
139
153
  pause_key: Optional[str] = None
140
154
  run_input_keyset: Optional[Dict[str, str]] = None
@@ -151,10 +165,10 @@ class State(ObjectBaseModel, Generic[R]):
151
165
 
152
166
  type: StateType
153
167
  name: Optional[str] = Field(default=None)
154
- timestamp: DateTimeTZ = Field(default_factory=lambda: pendulum.now("UTC"))
168
+ timestamp: DateTime = Field(default_factory=lambda: pendulum.now("UTC"))
155
169
  message: Optional[str] = Field(default=None, examples=["Run started"])
156
170
  state_details: StateDetails = Field(default_factory=StateDetails)
157
- data: Union["BaseResult[R]", "DataDocument[R]", Any] = Field(
171
+ data: Union["BaseResult[R]", Any] = Field(
158
172
  default=None,
159
173
  )
160
174
 
@@ -167,7 +181,10 @@ class State(ObjectBaseModel, Generic[R]):
167
181
  ...
168
182
 
169
183
  def result(
170
- self, raise_on_failure: bool = True, fetch: Optional[bool] = None
184
+ self,
185
+ raise_on_failure: bool = True,
186
+ fetch: Optional[bool] = None,
187
+ retry_result_failure: bool = True,
171
188
  ) -> Union[R, Exception]:
172
189
  """
173
190
  Retrieve the result attached to this state.
@@ -179,6 +196,8 @@ class State(ObjectBaseModel, Generic[R]):
179
196
  results into data. For synchronous users, this defaults to `True`.
180
197
  For asynchronous users, this defaults to `False` for backwards
181
198
  compatibility.
199
+ retry_result_failure: a boolean specifying whether to retry on failures to
200
+ load the result from result storage
182
201
 
183
202
  Raises:
184
203
  TypeError: If the state is failed but the result is not an exception.
@@ -241,7 +260,12 @@ class State(ObjectBaseModel, Generic[R]):
241
260
  """
242
261
  from prefect.states import get_state_result
243
262
 
244
- return get_state_result(self, raise_on_failure=raise_on_failure, fetch=fetch)
263
+ return get_state_result(
264
+ self,
265
+ raise_on_failure=raise_on_failure,
266
+ fetch=fetch,
267
+ retry_result_failure=retry_result_failure,
268
+ )
245
269
 
246
270
  def to_state_create(self):
247
271
  """
@@ -254,32 +278,35 @@ class State(ObjectBaseModel, Generic[R]):
254
278
  from prefect.client.schemas.actions import StateCreate
255
279
  from prefect.results import BaseResult
256
280
 
281
+ if isinstance(self.data, BaseResult) and self.data.serialize_to_none is False:
282
+ data = self.data
283
+ else:
284
+ data = None
285
+
257
286
  return StateCreate(
258
287
  type=self.type,
259
288
  name=self.name,
260
289
  message=self.message,
261
- data=self.data if isinstance(self.data, BaseResult) else None,
290
+ data=data,
262
291
  state_details=self.state_details,
263
292
  )
264
293
 
265
- @validator("name", always=True)
266
- def default_name_from_type(cls, v, *, values, **kwargs):
267
- return get_or_create_state_name(v, values)
268
-
269
- @root_validator
270
- def default_scheduled_start_time(cls, values):
271
- """
272
- TODO: This should throw an error instead of setting a default but is out of
273
- scope for https://github.com/PrefectHQ/orion/pull/174/ and can be rolled
274
- into work refactoring state initialization
275
- """
276
- if values.get("type") == StateType.SCHEDULED:
277
- state_details = values.setdefault(
278
- "state_details", cls.__fields__["state_details"].get_default()
279
- )
280
- if not state_details.scheduled_time:
281
- state_details.scheduled_time = pendulum.now("utc")
282
- return values
294
+ @model_validator(mode="after")
295
+ def default_name_from_type(self) -> Self:
296
+ """If a name is not provided, use the type"""
297
+ # if `type` is not in `values` it means the `type` didn't pass its own
298
+ # validation check and an error will be raised after this function is called
299
+ name = self.name
300
+ if name is None and self.type:
301
+ self.name = " ".join([v.capitalize() for v in self.type.value.split("_")])
302
+ return self
303
+
304
+ @model_validator(mode="after")
305
+ def default_scheduled_start_time(self) -> Self:
306
+ if self.type == StateType.SCHEDULED:
307
+ if not self.state_details.scheduled_time:
308
+ self.state_details.scheduled_time = DateTime.now("utc")
309
+ return self
283
310
 
284
311
  def is_scheduled(self) -> bool:
285
312
  return self.type == StateType.SCHEDULED
@@ -306,30 +333,35 @@ class State(ObjectBaseModel, Generic[R]):
306
333
  return self.type == StateType.CANCELLING
307
334
 
308
335
  def is_final(self) -> bool:
309
- return self.type in {
310
- StateType.CANCELLED,
311
- StateType.FAILED,
312
- StateType.COMPLETED,
313
- StateType.CRASHED,
314
- }
336
+ return self.type in TERMINAL_STATES
315
337
 
316
338
  def is_paused(self) -> bool:
317
339
  return self.type == StateType.PAUSED
318
340
 
319
- def copy(
320
- self,
321
- *,
322
- update: Optional[Dict[str, Any]] = None,
323
- reset_fields: bool = False,
324
- **kwargs,
341
+ def model_copy(
342
+ self, *, update: Optional[Dict[str, Any]] = None, deep: bool = False
325
343
  ):
326
344
  """
327
345
  Copying API models should return an object that could be inserted into the
328
346
  database again. The 'timestamp' is reset using the default factory.
329
347
  """
330
348
  update = update or {}
331
- update.setdefault("timestamp", self.__fields__["timestamp"].get_default())
332
- return super().copy(reset_fields=reset_fields, update=update, **kwargs)
349
+ update.setdefault("timestamp", self.model_fields["timestamp"].get_default())
350
+ return super().model_copy(update=update, deep=deep)
351
+
352
+ def fresh_copy(self, **kwargs) -> Self:
353
+ """
354
+ Return a fresh copy of the state with a new ID.
355
+ """
356
+ return self.model_copy(
357
+ update={
358
+ "id": uuid4(),
359
+ "created": pendulum.now("utc"),
360
+ "updated": pendulum.now("utc"),
361
+ "timestamp": pendulum.now("utc"),
362
+ },
363
+ **kwargs,
364
+ )
333
365
 
334
366
  def __repr__(self) -> str:
335
367
  """
@@ -338,12 +370,7 @@ class State(ObjectBaseModel, Generic[R]):
338
370
 
339
371
  `MyCompletedState(message="my message", type=COMPLETED, result=...)`
340
372
  """
341
- from prefect.deprecated.data_documents import DataDocument
342
-
343
- if isinstance(self.data, DataDocument):
344
- result = self.data.decode()
345
- else:
346
- result = self.data
373
+ result = self.data
347
374
 
348
375
  display = dict(
349
376
  message=repr(self.message),
@@ -411,9 +438,12 @@ class FlowRunPolicy(PrefectBaseModel):
411
438
  default=False, description="Indicates if this run is resuming from a pause."
412
439
  )
413
440
 
414
- @root_validator
415
- def populate_deprecated_fields(cls, values):
416
- return set_run_policy_deprecated_fields(values)
441
+ @model_validator(mode="before")
442
+ @classmethod
443
+ def populate_deprecated_fields(cls, values: Any):
444
+ if isinstance(values, dict):
445
+ return set_run_policy_deprecated_fields(values)
446
+ return values
417
447
 
418
448
 
419
449
  class FlowRun(ObjectBaseModel):
@@ -480,18 +510,18 @@ class FlowRun(ObjectBaseModel):
480
510
  run_count: int = Field(
481
511
  default=0, description="The number of times the flow run was executed."
482
512
  )
483
- expected_start_time: Optional[DateTimeTZ] = Field(
513
+ expected_start_time: Optional[DateTime] = Field(
484
514
  default=None,
485
515
  description="The flow run's expected start time.",
486
516
  )
487
- next_scheduled_start_time: Optional[DateTimeTZ] = Field(
517
+ next_scheduled_start_time: Optional[DateTime] = Field(
488
518
  default=None,
489
519
  description="The next time the flow run is scheduled to start.",
490
520
  )
491
- start_time: Optional[DateTimeTZ] = Field(
521
+ start_time: Optional[DateTime] = Field(
492
522
  default=None, description="The actual start time."
493
523
  )
494
- end_time: Optional[DateTimeTZ] = Field(
524
+ end_time: Optional[DateTime] = Field(
495
525
  default=None, description="The actual end time."
496
526
  )
497
527
  total_run_time: datetime.timedelta = Field(
@@ -530,7 +560,7 @@ class FlowRun(ObjectBaseModel):
530
560
  )
531
561
 
532
562
  work_pool_id: Optional[UUID] = Field(
533
- description="The work pool with which the queue is associated."
563
+ default=None, description="The work pool with which the queue is associated."
534
564
  )
535
565
  work_pool_name: Optional[str] = Field(
536
566
  default=None,
@@ -540,10 +570,11 @@ class FlowRun(ObjectBaseModel):
540
570
  state: Optional[State] = Field(
541
571
  default=None,
542
572
  description="The state of the flow run.",
543
- examples=[State(type=StateType.COMPLETED)],
573
+ examples=["State(type=StateType.COMPLETED)"],
544
574
  )
545
575
  job_variables: Optional[dict] = Field(
546
- default=None, description="Job variables for the flow run."
576
+ default=None,
577
+ description="Job variables for the flow run.",
547
578
  )
548
579
 
549
580
  # These are server-side optimizations and should not be present on client models
@@ -565,12 +596,13 @@ class FlowRun(ObjectBaseModel):
565
596
  """
566
597
  if isinstance(other, FlowRun):
567
598
  exclude_fields = {"estimated_run_time", "estimated_start_time_delta"}
568
- return self.dict(exclude=exclude_fields) == other.dict(
599
+ return self.model_dump(exclude=exclude_fields) == other.model_dump(
569
600
  exclude=exclude_fields
570
601
  )
571
602
  return super().__eq__(other)
572
603
 
573
- @validator("name", pre=True)
604
+ @field_validator("name", mode="before")
605
+ @classmethod
574
606
  def set_default_name(cls, name):
575
607
  return get_or_create_run_name(name)
576
608
 
@@ -603,15 +635,32 @@ class TaskRunPolicy(PrefectBaseModel):
603
635
  default=None, description="Determines the amount a retry should jitter"
604
636
  )
605
637
 
606
- @root_validator
607
- def populate_deprecated_fields(cls, values):
608
- return set_run_policy_deprecated_fields(values)
638
+ @model_validator(mode="after")
639
+ def populate_deprecated_fields(self):
640
+ """
641
+ If deprecated fields are provided, populate the corresponding new fields
642
+ to preserve orchestration behavior.
643
+ """
644
+ # We have marked these fields as deprecated, so we need to filter out the
645
+ # deprecation warnings _we're_ generating here
646
+ with warnings.catch_warnings():
647
+ warnings.simplefilter("ignore", DeprecationWarning)
648
+
649
+ if not self.retries and self.max_retries != 0:
650
+ self.retries = self.max_retries
609
651
 
610
- @validator("retry_delay")
652
+ if not self.retry_delay and self.retry_delay_seconds != 0:
653
+ self.retry_delay = self.retry_delay_seconds
654
+
655
+ return self
656
+
657
+ @field_validator("retry_delay")
658
+ @classmethod
611
659
  def validate_configured_retry_delays(cls, v):
612
660
  return list_length_50_or_less(v)
613
661
 
614
- @validator("retry_jitter_factor")
662
+ @field_validator("retry_jitter_factor")
663
+ @classmethod
615
664
  def validate_jitter_factor(cls, v):
616
665
  return validate_not_negative(v)
617
666
 
@@ -622,9 +671,7 @@ class TaskRunInput(PrefectBaseModel):
622
671
  could include, constants, parameters, or other task runs.
623
672
  """
624
673
 
625
- # freeze TaskRunInputs to allow them to be placed in sets
626
- class Config:
627
- frozen = True
674
+ model_config = ConfigDict(frozen=True)
628
675
 
629
676
  input_type: str
630
677
 
@@ -675,7 +722,7 @@ class TaskRun(ObjectBaseModel):
675
722
  " the task run."
676
723
  ),
677
724
  )
678
- cache_expiration: Optional[DateTimeTZ] = Field(
725
+ cache_expiration: Optional[DateTime] = Field(
679
726
  default=None, description="Specifies when the cached state should expire."
680
727
  )
681
728
  task_version: Optional[str] = Field(
@@ -716,21 +763,21 @@ class TaskRun(ObjectBaseModel):
716
763
  " associated with."
717
764
  ),
718
765
  )
719
- expected_start_time: Optional[DateTimeTZ] = Field(
766
+ expected_start_time: Optional[DateTime] = Field(
720
767
  default=None,
721
768
  description="The task run's expected start time.",
722
769
  )
723
770
 
724
771
  # the next scheduled start time will be populated
725
772
  # whenever the run is in a scheduled state
726
- next_scheduled_start_time: Optional[DateTimeTZ] = Field(
773
+ next_scheduled_start_time: Optional[DateTime] = Field(
727
774
  default=None,
728
775
  description="The next time the task run is scheduled to start.",
729
776
  )
730
- start_time: Optional[DateTimeTZ] = Field(
777
+ start_time: Optional[DateTime] = Field(
731
778
  default=None, description="The actual start time."
732
779
  )
733
- end_time: Optional[DateTimeTZ] = Field(
780
+ end_time: Optional[DateTime] = Field(
734
781
  default=None, description="The actual end time."
735
782
  )
736
783
  total_run_time: datetime.timedelta = Field(
@@ -751,11 +798,12 @@ class TaskRun(ObjectBaseModel):
751
798
 
752
799
  state: Optional[State] = Field(
753
800
  default=None,
754
- description="The state of the flow run.",
755
- examples=[State(type=StateType.COMPLETED)],
801
+ description="The state of the task run.",
802
+ examples=["State(type=StateType.COMPLETED)"],
756
803
  )
757
804
 
758
- @validator("name", pre=True)
805
+ @field_validator("name", mode="before")
806
+ @classmethod
759
807
  def set_default_name(cls, name):
760
808
  return get_or_create_run_name(name)
761
809
 
@@ -774,9 +822,7 @@ class Workspace(PrefectBaseModel):
774
822
  workspace_name: str = Field(..., description="The workspace name.")
775
823
  workspace_description: str = Field(..., description="Description of the workspace.")
776
824
  workspace_handle: str = Field(..., description="The workspace's unique handle.")
777
-
778
- class Config:
779
- extra = "ignore"
825
+ model_config = ConfigDict(extra="ignore")
780
826
 
781
827
  @property
782
828
  def handle(self) -> str:
@@ -809,10 +855,39 @@ class Workspace(PrefectBaseModel):
809
855
  return hash(self.handle)
810
856
 
811
857
 
858
+ class IPAllowlistEntry(PrefectBaseModel):
859
+ ip_network: IPvAnyNetwork
860
+ enabled: bool
861
+ description: Optional[str] = Field(
862
+ default=None, description="A description of the IP entry."
863
+ )
864
+ last_seen: Optional[str] = Field(
865
+ default=None,
866
+ description="The last time this IP was seen accessing Prefect Cloud.",
867
+ )
868
+
869
+
870
+ class IPAllowlist(PrefectBaseModel):
871
+ """
872
+ A Prefect Cloud IP allowlist.
873
+
874
+ Expected payload for an IP allowlist from the Prefect Cloud API.
875
+ """
876
+
877
+ entries: List[IPAllowlistEntry]
878
+
879
+
880
+ class IPAllowlistMyAccessResponse(PrefectBaseModel):
881
+ """Expected payload for an IP allowlist access response from the Prefect Cloud API."""
882
+
883
+ allowed: bool
884
+ detail: str
885
+
886
+
812
887
  class BlockType(ObjectBaseModel):
813
888
  """An ORM representation of a block type"""
814
889
 
815
- name: str = Field(default=..., description="A block type's name")
890
+ name: Name = Field(default=..., description="A block type's name")
816
891
  slug: str = Field(default=..., description="A block type's slug")
817
892
  logo_url: Optional[HttpUrl] = Field(
818
893
  default=None, description="Web URL for the block type's logo"
@@ -832,10 +907,6 @@ class BlockType(ObjectBaseModel):
832
907
  default=False, description="Protected block types cannot be modified via API."
833
908
  )
834
909
 
835
- @validator("name", check_fields=False)
836
- def validate_name_characters(cls, v):
837
- return raise_on_name_with_banned_characters(v)
838
-
839
910
 
840
911
  class BlockSchema(ObjectBaseModel):
841
912
  """A representation of a block schema."""
@@ -861,7 +932,7 @@ class BlockSchema(ObjectBaseModel):
861
932
  class BlockDocument(ObjectBaseModel):
862
933
  """An ORM representation of a block document."""
863
934
 
864
- name: Optional[str] = Field(
935
+ name: Optional[Name] = Field(
865
936
  default=None,
866
937
  description=(
867
938
  "The block document's name. Not required for anonymous block documents."
@@ -890,21 +961,29 @@ class BlockDocument(ObjectBaseModel):
890
961
  ),
891
962
  )
892
963
 
893
- @validator("name", check_fields=False)
894
- def validate_name_characters(cls, v):
895
- # the BlockDocumentCreate subclass allows name=None
896
- # and will inherit this validator
897
- return raise_on_name_with_banned_characters(v)
964
+ _validate_name_format = field_validator("name")(validate_block_document_name)
898
965
 
899
- @root_validator
966
+ @model_validator(mode="before")
967
+ @classmethod
900
968
  def validate_name_is_present_if_not_anonymous(cls, values):
901
969
  return validate_name_present_on_nonanonymous_blocks(values)
902
970
 
971
+ @model_serializer(mode="wrap")
972
+ def serialize_data(
973
+ self, handler: ModelWrapValidatorHandler, info: SerializationInfo
974
+ ):
975
+ self.data = visit_collection(
976
+ self.data,
977
+ visit_fn=partial(handle_secret_render, context=info.context or {}),
978
+ return_data=True,
979
+ )
980
+ return handler(self)
981
+
903
982
 
904
983
  class Flow(ObjectBaseModel):
905
984
  """An ORM representation of flow data."""
906
985
 
907
- name: str = Field(
986
+ name: Name = Field(
908
987
  default=..., description="The name of the flow", examples=["my-flow"]
909
988
  )
910
989
  tags: List[str] = Field(
@@ -913,23 +992,6 @@ class Flow(ObjectBaseModel):
913
992
  examples=[["tag-1", "tag-2"]],
914
993
  )
915
994
 
916
- @validator("name", check_fields=False)
917
- def validate_name_characters(cls, v):
918
- return raise_on_name_with_banned_characters(v)
919
-
920
-
921
- @deprecated_class(
922
- start_date="Jun 2024",
923
- help="Will be removed in Prefect 3 in favor of prefect.client.schemas.actions.DeploymentScheduleCreate",
924
- )
925
- class MinimalDeploymentSchedule(PrefectBaseModel):
926
- schedule: SCHEDULE_TYPES = Field(
927
- default=..., description="The schedule for the deployment."
928
- )
929
- active: bool = Field(
930
- default=True, description="Whether or not the schedule is active."
931
- )
932
-
933
995
 
934
996
  class DeploymentSchedule(ObjectBaseModel):
935
997
  deployment_id: Optional[UUID] = Field(
@@ -956,10 +1018,10 @@ class DeploymentSchedule(ObjectBaseModel):
956
1018
  )
957
1019
 
958
1020
 
959
- class Deployment(DeprecatedInfraOverridesField, ObjectBaseModel):
1021
+ class Deployment(ObjectBaseModel):
960
1022
  """An ORM representation of deployment data."""
961
1023
 
962
- name: str = Field(default=..., description="The name of the deployment.")
1024
+ name: Name = Field(default=..., description="The name of the deployment.")
963
1025
  version: Optional[str] = Field(
964
1026
  default=None, description="An optional version for the deployment."
965
1027
  )
@@ -969,15 +1031,12 @@ class Deployment(DeprecatedInfraOverridesField, ObjectBaseModel):
969
1031
  flow_id: UUID = Field(
970
1032
  default=..., description="The flow id associated with the deployment."
971
1033
  )
972
- schedule: Optional[SCHEDULE_TYPES] = Field(
973
- default=None, description="A schedule for the deployment."
974
- )
975
- is_schedule_active: bool = Field(
976
- default=True, description="Whether or not the deployment schedule is active."
977
- )
978
1034
  paused: bool = Field(
979
1035
  default=False, description="Whether or not the deployment is paused."
980
1036
  )
1037
+ concurrency_limit: Optional[int] = Field(
1038
+ default=None, description="The concurrency limit for the deployment."
1039
+ )
981
1040
  schedules: List[DeploymentSchedule] = Field(
982
1041
  default_factory=list, description="A list of schedules for the deployment."
983
1042
  )
@@ -1005,7 +1064,7 @@ class Deployment(DeprecatedInfraOverridesField, ObjectBaseModel):
1005
1064
  " be scheduled."
1006
1065
  ),
1007
1066
  )
1008
- last_polled: Optional[DateTimeTZ] = Field(
1067
+ last_polled: Optional[DateTime] = Field(
1009
1068
  default=None,
1010
1069
  description="The last time the deployment was polled for status updates.",
1011
1070
  )
@@ -1026,12 +1085,6 @@ class Deployment(DeprecatedInfraOverridesField, ObjectBaseModel):
1026
1085
  "The path to the entrypoint for the workflow, relative to the `path`."
1027
1086
  ),
1028
1087
  )
1029
- manifest_path: Optional[str] = Field(
1030
- default=None,
1031
- description=(
1032
- "The path to the flow's manifest file, relative to the chosen storage."
1033
- ),
1034
- )
1035
1088
  storage_document_id: Optional[UUID] = Field(
1036
1089
  default=None,
1037
1090
  description="The block document defining storage used for this flow.",
@@ -1048,23 +1101,19 @@ class Deployment(DeprecatedInfraOverridesField, ObjectBaseModel):
1048
1101
  default=None,
1049
1102
  description="Optional information about the updater of this deployment.",
1050
1103
  )
1051
- work_queue_id: UUID = Field(
1104
+ work_queue_id: Optional[UUID] = Field(
1052
1105
  default=None,
1053
1106
  description=(
1054
1107
  "The id of the work pool queue to which this deployment is assigned."
1055
1108
  ),
1056
1109
  )
1057
1110
  enforce_parameter_schema: bool = Field(
1058
- default=False,
1111
+ default=True,
1059
1112
  description=(
1060
1113
  "Whether or not the deployment should enforce the parameter schema."
1061
1114
  ),
1062
1115
  )
1063
1116
 
1064
- @validator("name", check_fields=False)
1065
- def validate_name_characters(cls, v):
1066
- return raise_on_name_with_banned_characters(v)
1067
-
1068
1117
 
1069
1118
  class ConcurrencyLimit(ObjectBaseModel):
1070
1119
  """An ORM representation of a concurrency limit."""
@@ -1139,9 +1188,12 @@ class BlockDocumentReference(ObjectBaseModel):
1139
1188
  default=..., description="The name that the reference is nested under"
1140
1189
  )
1141
1190
 
1142
- @root_validator
1191
+ @model_validator(mode="before")
1192
+ @classmethod
1143
1193
  def validate_parent_and_ref_are_different(cls, values):
1144
- return validate_parent_and_ref_diff(values)
1194
+ if isinstance(values, dict):
1195
+ return validate_parent_and_ref_diff(values)
1196
+ return values
1145
1197
 
1146
1198
 
1147
1199
  class Configuration(ObjectBaseModel):
@@ -1183,7 +1235,7 @@ class Log(ObjectBaseModel):
1183
1235
  name: str = Field(default=..., description="The logger name.")
1184
1236
  level: int = Field(default=..., description="The log level.")
1185
1237
  message: str = Field(default=..., description="The log message.")
1186
- timestamp: DateTimeTZ = Field(default=..., description="The log timestamp.")
1238
+ timestamp: DateTime = Field(default=..., description="The log timestamp.")
1187
1239
  flow_run_id: Optional[UUID] = Field(
1188
1240
  default=None, description="The flow run ID associated with the log."
1189
1241
  )
@@ -1208,7 +1260,7 @@ class QueueFilter(PrefectBaseModel):
1208
1260
  class WorkQueue(ObjectBaseModel):
1209
1261
  """An ORM representation of a work queue"""
1210
1262
 
1211
- name: str = Field(default=..., description="The name of the work queue.")
1263
+ name: Name = Field(default=..., description="The name of the work queue.")
1212
1264
  description: Optional[str] = Field(
1213
1265
  default="", description="An optional description for the work queue."
1214
1266
  )
@@ -1234,17 +1286,13 @@ class WorkQueue(ObjectBaseModel):
1234
1286
  description="DEPRECATED: Filter criteria for the work queue.",
1235
1287
  deprecated=True,
1236
1288
  )
1237
- last_polled: Optional[DateTimeTZ] = Field(
1289
+ last_polled: Optional[DateTime] = Field(
1238
1290
  default=None, description="The last time an agent polled this queue for work."
1239
1291
  )
1240
1292
  status: Optional[WorkQueueStatus] = Field(
1241
1293
  default=None, description="The queue status."
1242
1294
  )
1243
1295
 
1244
- @validator("name", check_fields=False)
1245
- def validate_name_characters(cls, v):
1246
- return raise_on_name_with_banned_characters(v)
1247
-
1248
1296
 
1249
1297
  class WorkQueueHealthPolicy(PrefectBaseModel):
1250
1298
  maximum_late_runs: Optional[int] = Field(
@@ -1263,7 +1311,7 @@ class WorkQueueHealthPolicy(PrefectBaseModel):
1263
1311
  )
1264
1312
 
1265
1313
  def evaluate_health_status(
1266
- self, late_runs_count: int, last_polled: Optional[DateTimeTZ] = None
1314
+ self, late_runs_count: int, last_polled: Optional[DateTime] = None
1267
1315
  ) -> bool:
1268
1316
  """
1269
1317
  Given empirical information about the state of the work queue, evaluate its health status.
@@ -1298,7 +1346,7 @@ class WorkQueueStatusDetail(PrefectBaseModel):
1298
1346
  late_runs_count: int = Field(
1299
1347
  default=0, description="The number of late flow runs in the work queue."
1300
1348
  )
1301
- last_polled: Optional[DateTimeTZ] = Field(
1349
+ last_polled: Optional[DateTime] = Field(
1302
1350
  default=None, description="The last time an agent polled this queue for work."
1303
1351
  )
1304
1352
  health_check_policy: WorkQueueHealthPolicy = Field(
@@ -1338,7 +1386,8 @@ class FlowRunNotificationPolicy(ObjectBaseModel):
1338
1386
  ],
1339
1387
  )
1340
1388
 
1341
- @validator("message_template")
1389
+ @field_validator("message_template")
1390
+ @classmethod
1342
1391
  def validate_message_template_variables(cls, v):
1343
1392
  return validate_message_template_variables(v)
1344
1393
 
@@ -1356,7 +1405,7 @@ class Agent(ObjectBaseModel):
1356
1405
  work_queue_id: UUID = Field(
1357
1406
  default=..., description="The work queue with which the agent is associated."
1358
1407
  )
1359
- last_activity_time: Optional[DateTimeTZ] = Field(
1408
+ last_activity_time: Optional[DateTime] = Field(
1360
1409
  default=None, description="The last time this agent polled for work."
1361
1410
  )
1362
1411
 
@@ -1364,7 +1413,7 @@ class Agent(ObjectBaseModel):
1364
1413
  class WorkPool(ObjectBaseModel):
1365
1414
  """An ORM representation of a work pool"""
1366
1415
 
1367
- name: str = Field(
1416
+ name: Name = Field(
1368
1417
  description="The name of the work pool.",
1369
1418
  )
1370
1419
  description: Optional[str] = Field(
@@ -1399,11 +1448,8 @@ class WorkPool(ObjectBaseModel):
1399
1448
  def is_managed_pool(self) -> bool:
1400
1449
  return self.type.endswith(":managed")
1401
1450
 
1402
- @validator("name", check_fields=False)
1403
- def validate_name_characters(cls, v):
1404
- return raise_on_name_with_banned_characters(v)
1405
-
1406
- @validator("default_queue_id", always=True)
1451
+ @field_validator("default_queue_id")
1452
+ @classmethod
1407
1453
  def helpful_error_for_missing_default_queue_id(cls, v):
1408
1454
  return validate_default_queue_id_not_none(v)
1409
1455
 
@@ -1430,8 +1476,8 @@ class Worker(ObjectBaseModel):
1430
1476
  )
1431
1477
 
1432
1478
 
1433
- Flow.update_forward_refs()
1434
- FlowRun.update_forward_refs()
1479
+ Flow.model_rebuild()
1480
+ # FlowRun.model_rebuild()
1435
1481
 
1436
1482
 
1437
1483
  class Artifact(ObjectBaseModel):
@@ -1470,7 +1516,8 @@ class Artifact(ObjectBaseModel):
1470
1516
  default=None, description="The task run associated with the artifact."
1471
1517
  )
1472
1518
 
1473
- @validator("metadata_")
1519
+ @field_validator("metadata_")
1520
+ @classmethod
1474
1521
  def validate_metadata_length(cls, v):
1475
1522
  return validate_max_metadata_length(v)
1476
1523
 
@@ -1519,11 +1566,10 @@ class Variable(ObjectBaseModel):
1519
1566
  examples=["my_variable"],
1520
1567
  max_length=MAX_VARIABLE_NAME_LENGTH,
1521
1568
  )
1522
- value: str = Field(
1569
+ value: StrictVariableValue = Field(
1523
1570
  default=...,
1524
1571
  description="The value of the variable",
1525
1572
  examples=["my_value"],
1526
- max_length=MAX_VARIABLE_VALUE_LENGTH,
1527
1573
  )
1528
1574
  tags: List[str] = Field(
1529
1575
  default_factory=list,
@@ -1536,7 +1582,7 @@ class FlowRunInput(ObjectBaseModel):
1536
1582
  flow_run_id: UUID = Field(description="The flow run ID associated with the input.")
1537
1583
  key: str = Field(description="The key of the input.")
1538
1584
  value: str = Field(description="The value of the input.")
1539
- sender: Optional[str] = Field(description="The sender of the input.")
1585
+ sender: Optional[str] = Field(default=None, description="The sender of the input.")
1540
1586
 
1541
1587
  @property
1542
1588
  def decoded_value(self) -> Any:
@@ -1548,7 +1594,8 @@ class FlowRunInput(ObjectBaseModel):
1548
1594
  """
1549
1595
  return orjson.loads(self.value)
1550
1596
 
1551
- @validator("key", check_fields=False)
1597
+ @field_validator("key", check_fields=False)
1598
+ @classmethod
1552
1599
  def validate_name_characters(cls, v):
1553
1600
  raise_on_name_alphanumeric_dashes_only(v)
1554
1601
  return v
@@ -1589,6 +1636,9 @@ class CsrfToken(ObjectBaseModel):
1589
1636
  client: str = Field(
1590
1637
  default=..., description="The client id associated with the CSRF token"
1591
1638
  )
1592
- expiration: DateTimeTZ = Field(
1639
+ expiration: datetime.datetime = Field(
1593
1640
  default=..., description="The expiration time of the CSRF token"
1594
1641
  )
1642
+
1643
+
1644
+ __getattr__ = getattr_migration(__name__)