prefect-client 3.1.10__py3-none-any.whl → 3.1.12__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 (141) hide show
  1. prefect/_experimental/lineage.py +7 -8
  2. prefect/_experimental/sla/__init__.py +0 -0
  3. prefect/_experimental/sla/client.py +66 -0
  4. prefect/_experimental/sla/objects.py +53 -0
  5. prefect/_internal/_logging.py +15 -3
  6. prefect/_internal/compatibility/async_dispatch.py +22 -16
  7. prefect/_internal/compatibility/deprecated.py +42 -18
  8. prefect/_internal/compatibility/migration.py +2 -2
  9. prefect/_internal/concurrency/inspection.py +12 -14
  10. prefect/_internal/concurrency/primitives.py +2 -2
  11. prefect/_internal/concurrency/services.py +154 -80
  12. prefect/_internal/concurrency/waiters.py +13 -9
  13. prefect/_internal/pydantic/annotations/pendulum.py +7 -7
  14. prefect/_internal/pytz.py +4 -3
  15. prefect/_internal/retries.py +10 -5
  16. prefect/_internal/schemas/bases.py +19 -10
  17. prefect/_internal/schemas/validators.py +227 -388
  18. prefect/_version.py +3 -3
  19. prefect/automations.py +236 -30
  20. prefect/blocks/__init__.py +3 -3
  21. prefect/blocks/abstract.py +53 -30
  22. prefect/blocks/core.py +183 -84
  23. prefect/blocks/notifications.py +133 -73
  24. prefect/blocks/redis.py +13 -9
  25. prefect/blocks/system.py +24 -11
  26. prefect/blocks/webhook.py +7 -5
  27. prefect/cache_policies.py +3 -2
  28. prefect/client/orchestration/__init__.py +1957 -0
  29. prefect/client/orchestration/_artifacts/__init__.py +0 -0
  30. prefect/client/orchestration/_artifacts/client.py +239 -0
  31. prefect/client/orchestration/_automations/__init__.py +0 -0
  32. prefect/client/orchestration/_automations/client.py +329 -0
  33. prefect/client/orchestration/_blocks_documents/__init__.py +0 -0
  34. prefect/client/orchestration/_blocks_documents/client.py +334 -0
  35. prefect/client/orchestration/_blocks_schemas/__init__.py +0 -0
  36. prefect/client/orchestration/_blocks_schemas/client.py +200 -0
  37. prefect/client/orchestration/_blocks_types/__init__.py +0 -0
  38. prefect/client/orchestration/_blocks_types/client.py +380 -0
  39. prefect/client/orchestration/_concurrency_limits/__init__.py +0 -0
  40. prefect/client/orchestration/_concurrency_limits/client.py +762 -0
  41. prefect/client/orchestration/_deployments/__init__.py +0 -0
  42. prefect/client/orchestration/_deployments/client.py +1128 -0
  43. prefect/client/orchestration/_flow_runs/__init__.py +0 -0
  44. prefect/client/orchestration/_flow_runs/client.py +903 -0
  45. prefect/client/orchestration/_flows/__init__.py +0 -0
  46. prefect/client/orchestration/_flows/client.py +343 -0
  47. prefect/client/orchestration/_logs/__init__.py +0 -0
  48. prefect/client/orchestration/_logs/client.py +97 -0
  49. prefect/client/orchestration/_variables/__init__.py +0 -0
  50. prefect/client/orchestration/_variables/client.py +157 -0
  51. prefect/client/orchestration/base.py +46 -0
  52. prefect/client/orchestration/routes.py +145 -0
  53. prefect/client/schemas/__init__.py +68 -28
  54. prefect/client/schemas/actions.py +2 -2
  55. prefect/client/schemas/filters.py +5 -0
  56. prefect/client/schemas/objects.py +8 -15
  57. prefect/client/schemas/schedules.py +22 -10
  58. prefect/concurrency/_asyncio.py +87 -0
  59. prefect/concurrency/{events.py → _events.py} +10 -10
  60. prefect/concurrency/asyncio.py +20 -104
  61. prefect/concurrency/context.py +6 -4
  62. prefect/concurrency/services.py +26 -74
  63. prefect/concurrency/sync.py +23 -44
  64. prefect/concurrency/v1/_asyncio.py +63 -0
  65. prefect/concurrency/v1/{events.py → _events.py} +13 -15
  66. prefect/concurrency/v1/asyncio.py +27 -80
  67. prefect/concurrency/v1/context.py +6 -4
  68. prefect/concurrency/v1/services.py +33 -79
  69. prefect/concurrency/v1/sync.py +18 -37
  70. prefect/context.py +66 -45
  71. prefect/deployments/base.py +10 -144
  72. prefect/deployments/flow_runs.py +12 -2
  73. prefect/deployments/runner.py +53 -4
  74. prefect/deployments/steps/pull.py +13 -0
  75. prefect/engine.py +17 -4
  76. prefect/events/clients.py +7 -1
  77. prefect/events/schemas/events.py +3 -2
  78. prefect/filesystems.py +6 -2
  79. prefect/flow_engine.py +101 -85
  80. prefect/flows.py +10 -1
  81. prefect/input/run_input.py +2 -1
  82. prefect/logging/logging.yml +1 -1
  83. prefect/main.py +1 -3
  84. prefect/results.py +2 -307
  85. prefect/runner/runner.py +4 -2
  86. prefect/runner/storage.py +87 -21
  87. prefect/serializers.py +32 -25
  88. prefect/settings/legacy.py +4 -4
  89. prefect/settings/models/api.py +3 -3
  90. prefect/settings/models/cli.py +3 -3
  91. prefect/settings/models/client.py +5 -3
  92. prefect/settings/models/cloud.py +8 -3
  93. prefect/settings/models/deployments.py +3 -3
  94. prefect/settings/models/experiments.py +4 -7
  95. prefect/settings/models/flows.py +3 -3
  96. prefect/settings/models/internal.py +4 -2
  97. prefect/settings/models/logging.py +4 -3
  98. prefect/settings/models/results.py +3 -3
  99. prefect/settings/models/root.py +3 -2
  100. prefect/settings/models/runner.py +4 -4
  101. prefect/settings/models/server/api.py +3 -3
  102. prefect/settings/models/server/database.py +11 -4
  103. prefect/settings/models/server/deployments.py +6 -2
  104. prefect/settings/models/server/ephemeral.py +4 -2
  105. prefect/settings/models/server/events.py +3 -2
  106. prefect/settings/models/server/flow_run_graph.py +6 -2
  107. prefect/settings/models/server/root.py +3 -3
  108. prefect/settings/models/server/services.py +26 -11
  109. prefect/settings/models/server/tasks.py +6 -3
  110. prefect/settings/models/server/ui.py +3 -3
  111. prefect/settings/models/tasks.py +5 -5
  112. prefect/settings/models/testing.py +3 -3
  113. prefect/settings/models/worker.py +5 -3
  114. prefect/settings/profiles.py +15 -2
  115. prefect/states.py +61 -45
  116. prefect/task_engine.py +54 -75
  117. prefect/task_runners.py +56 -55
  118. prefect/task_worker.py +2 -2
  119. prefect/tasks.py +90 -36
  120. prefect/telemetry/bootstrap.py +10 -9
  121. prefect/telemetry/run_telemetry.py +13 -8
  122. prefect/telemetry/services.py +4 -0
  123. prefect/transactions.py +4 -15
  124. prefect/utilities/_git.py +34 -0
  125. prefect/utilities/asyncutils.py +1 -1
  126. prefect/utilities/engine.py +3 -19
  127. prefect/utilities/generics.py +18 -0
  128. prefect/utilities/templating.py +25 -1
  129. prefect/workers/base.py +6 -3
  130. prefect/workers/process.py +1 -1
  131. {prefect_client-3.1.10.dist-info → prefect_client-3.1.12.dist-info}/METADATA +2 -2
  132. {prefect_client-3.1.10.dist-info → prefect_client-3.1.12.dist-info}/RECORD +135 -109
  133. prefect/client/orchestration.py +0 -4523
  134. prefect/records/__init__.py +0 -1
  135. prefect/records/base.py +0 -235
  136. prefect/records/filesystem.py +0 -213
  137. prefect/records/memory.py +0 -184
  138. prefect/records/result_store.py +0 -70
  139. {prefect_client-3.1.10.dist-info → prefect_client-3.1.12.dist-info}/LICENSE +0 -0
  140. {prefect_client-3.1.10.dist-info → prefect_client-3.1.12.dist-info}/WHEEL +0 -0
  141. {prefect_client-3.1.10.dist-info → prefect_client-3.1.12.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,7 @@
1
1
  from datetime import timedelta
2
+ from typing import ClassVar
2
3
 
3
- from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic import AliasChoices, AliasPath, ConfigDict, Field
4
5
 
5
6
  from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
7
 
@@ -10,7 +11,7 @@ class ServerServicesCancellationCleanupSettings(PrefectBaseSettings):
10
11
  Settings for controlling the cancellation cleanup service
11
12
  """
12
13
 
13
- model_config = _build_settings_config(
14
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
14
15
  ("server", "services", "cancellation_cleanup")
15
16
  )
16
17
 
@@ -40,7 +41,9 @@ class ServerServicesEventPersisterSettings(PrefectBaseSettings):
40
41
  Settings for controlling the event persister service
41
42
  """
42
43
 
43
- model_config = _build_settings_config(("server", "services", "event_persister"))
44
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
45
+ ("server", "services", "event_persister")
46
+ )
44
47
 
45
48
  enabled: bool = Field(
46
49
  default=True,
@@ -80,7 +83,7 @@ class ServerServicesFlowRunNotificationsSettings(PrefectBaseSettings):
80
83
  Settings for controlling the flow run notifications service
81
84
  """
82
85
 
83
- model_config = _build_settings_config(
86
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
84
87
  ("server", "services", "flow_run_notifications")
85
88
  )
86
89
 
@@ -100,7 +103,9 @@ class ServerServicesForemanSettings(PrefectBaseSettings):
100
103
  Settings for controlling the foreman service
101
104
  """
102
105
 
103
- model_config = _build_settings_config(("server", "services", "foreman"))
106
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
107
+ ("server", "services", "foreman")
108
+ )
104
109
 
105
110
  enabled: bool = Field(
106
111
  default=True,
@@ -179,7 +184,9 @@ class ServerServicesLateRunsSettings(PrefectBaseSettings):
179
184
  Settings for controlling the late runs service
180
185
  """
181
186
 
182
- model_config = _build_settings_config(("server", "services", "late_runs"))
187
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
188
+ ("server", "services", "late_runs")
189
+ )
183
190
 
184
191
  enabled: bool = Field(
185
192
  default=True,
@@ -221,7 +228,9 @@ class ServerServicesSchedulerSettings(PrefectBaseSettings):
221
228
  Settings for controlling the scheduler service
222
229
  """
223
230
 
224
- model_config = _build_settings_config(("server", "services", "scheduler"))
231
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
232
+ ("server", "services", "scheduler")
233
+ )
225
234
 
226
235
  enabled: bool = Field(
227
236
  default=True,
@@ -344,7 +353,9 @@ class ServerServicesPauseExpirationsSettings(PrefectBaseSettings):
344
353
  Settings for controlling the pause expiration service
345
354
  """
346
355
 
347
- model_config = _build_settings_config(("server", "services", "pause_expirations"))
356
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
357
+ ("server", "services", "pause_expirations")
358
+ )
348
359
 
349
360
  enabled: bool = Field(
350
361
  default=True,
@@ -378,7 +389,9 @@ class ServerServicesTaskRunRecorderSettings(PrefectBaseSettings):
378
389
  Settings for controlling the task run recorder service
379
390
  """
380
391
 
381
- model_config = _build_settings_config(("server", "services", "task_run_recorder"))
392
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
393
+ ("server", "services", "task_run_recorder")
394
+ )
382
395
 
383
396
  enabled: bool = Field(
384
397
  default=True,
@@ -396,7 +409,9 @@ class ServerServicesTriggersSettings(PrefectBaseSettings):
396
409
  Settings for controlling the triggers service
397
410
  """
398
411
 
399
- model_config = _build_settings_config(("server", "services", "triggers"))
412
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
413
+ ("server", "services", "triggers")
414
+ )
400
415
 
401
416
  enabled: bool = Field(
402
417
  default=True,
@@ -414,7 +429,7 @@ class ServerServicesSettings(PrefectBaseSettings):
414
429
  Settings for controlling server services
415
430
  """
416
431
 
417
- model_config = _build_settings_config(("server", "services"))
432
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("server", "services"))
418
433
 
419
434
  cancellation_cleanup: ServerServicesCancellationCleanupSettings = Field(
420
435
  default_factory=ServerServicesCancellationCleanupSettings,
@@ -1,6 +1,7 @@
1
1
  from datetime import timedelta
2
+ from typing import ClassVar
2
3
 
3
- from pydantic import AliasChoices, AliasPath, Field
4
+ from pydantic import AliasChoices, AliasPath, ConfigDict, Field
4
5
 
5
6
  from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
7
 
@@ -10,7 +11,9 @@ class ServerTasksSchedulingSettings(PrefectBaseSettings):
10
11
  Settings for controlling server-side behavior related to task scheduling
11
12
  """
12
13
 
13
- model_config = _build_settings_config(("server", "tasks", "scheduling"))
14
+ model_config: ClassVar[ConfigDict] = _build_settings_config(
15
+ ("server", "tasks", "scheduling")
16
+ )
14
17
 
15
18
  max_scheduled_queue_size: int = Field(
16
19
  default=1000,
@@ -48,7 +51,7 @@ class ServerTasksSettings(PrefectBaseSettings):
48
51
  Settings for controlling server-side behavior related to tasks
49
52
  """
50
53
 
51
- model_config = _build_settings_config(("server", "tasks"))
54
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("server", "tasks"))
52
55
 
53
56
  tag_concurrency_slot_wait_seconds: float = Field(
54
57
  default=30,
@@ -1,12 +1,12 @@
1
- from typing import Optional
1
+ from typing import ClassVar, Optional
2
2
 
3
- from pydantic import AliasChoices, AliasPath, Field
3
+ from pydantic import AliasChoices, AliasPath, ConfigDict, Field
4
4
 
5
5
  from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
6
 
7
7
 
8
8
  class ServerUISettings(PrefectBaseSettings):
9
- model_config = _build_settings_config(("server", "ui"))
9
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("server", "ui"))
10
10
 
11
11
  enabled: bool = Field(
12
12
  default=True,
@@ -1,12 +1,12 @@
1
- from typing import Optional, Union
1
+ from typing import ClassVar, Optional, Union
2
2
 
3
- from pydantic import AliasChoices, AliasPath, Field
3
+ from pydantic import AliasChoices, AliasPath, ConfigDict, Field
4
4
 
5
5
  from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
6
 
7
7
 
8
8
  class TasksRunnerSettings(PrefectBaseSettings):
9
- model_config = _build_settings_config(("tasks", "runner"))
9
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("tasks", "runner"))
10
10
 
11
11
  thread_pool_max_workers: Optional[int] = Field(
12
12
  default=None,
@@ -21,7 +21,7 @@ class TasksRunnerSettings(PrefectBaseSettings):
21
21
 
22
22
 
23
23
  class TasksSchedulingSettings(PrefectBaseSettings):
24
- model_config = _build_settings_config(("tasks", "scheduling"))
24
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("tasks", "scheduling"))
25
25
 
26
26
  default_storage_block: Optional[str] = Field(
27
27
  default=None,
@@ -45,7 +45,7 @@ class TasksSchedulingSettings(PrefectBaseSettings):
45
45
 
46
46
 
47
47
  class TasksSettings(PrefectBaseSettings):
48
- model_config = _build_settings_config(("tasks",))
48
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("tasks",))
49
49
 
50
50
  refresh_cache: bool = Field(
51
51
  default=False,
@@ -1,12 +1,12 @@
1
- from typing import Any, Optional
1
+ from typing import Any, ClassVar, Optional
2
2
 
3
- from pydantic import AliasChoices, AliasPath, Field
3
+ from pydantic import AliasChoices, AliasPath, ConfigDict, Field
4
4
 
5
5
  from prefect.settings.base import PrefectBaseSettings, _build_settings_config
6
6
 
7
7
 
8
8
  class TestingSettings(PrefectBaseSettings):
9
- model_config = _build_settings_config(("testing",))
9
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("testing",))
10
10
 
11
11
  test_mode: bool = Field(
12
12
  default=False,
@@ -1,10 +1,12 @@
1
- from pydantic import Field
1
+ from typing import ClassVar
2
+
3
+ from pydantic import ConfigDict, Field
2
4
 
3
5
  from prefect.settings.base import PrefectBaseSettings, _build_settings_config
4
6
 
5
7
 
6
8
  class WorkerWebserverSettings(PrefectBaseSettings):
7
- model_config = _build_settings_config(("worker", "webserver"))
9
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("worker", "webserver"))
8
10
 
9
11
  host: str = Field(
10
12
  default="0.0.0.0",
@@ -18,7 +20,7 @@ class WorkerWebserverSettings(PrefectBaseSettings):
18
20
 
19
21
 
20
22
  class WorkerSettings(PrefectBaseSettings):
21
- model_config = _build_settings_config(("worker",))
23
+ model_config: ClassVar[ConfigDict] = _build_settings_config(("worker",))
22
24
 
23
25
  heartbeat_seconds: float = Field(
24
26
  default=30,
@@ -1,7 +1,18 @@
1
1
  import inspect
2
2
  import warnings
3
3
  from pathlib import Path
4
- from typing import Annotated, Any, Dict, Iterable, List, Optional, Set, Tuple, Union
4
+ from typing import (
5
+ Annotated,
6
+ Any,
7
+ ClassVar,
8
+ Dict,
9
+ Iterable,
10
+ List,
11
+ Optional,
12
+ Set,
13
+ Tuple,
14
+ Union,
15
+ )
5
16
 
6
17
  import toml
7
18
  from pydantic import (
@@ -48,7 +59,9 @@ def _cast_settings(
48
59
  class Profile(BaseModel):
49
60
  """A user profile containing settings."""
50
61
 
51
- model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True)
62
+ model_config: ClassVar[ConfigDict] = ConfigDict(
63
+ extra="ignore", arbitrary_types_allowed=True
64
+ )
52
65
 
53
66
  name: str
54
67
  settings: Annotated[Dict[Setting, Any], BeforeValidator(_cast_settings)] = Field(
prefect/states.py CHANGED
@@ -6,7 +6,7 @@ import uuid
6
6
  import warnings
7
7
  from collections import Counter
8
8
  from types import GeneratorType, TracebackType
9
- from typing import Any, Dict, Iterable, Optional, Type
9
+ from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Type
10
10
 
11
11
  import anyio
12
12
  import httpx
@@ -28,17 +28,16 @@ from prefect.exceptions import (
28
28
  UnfinishedRun,
29
29
  )
30
30
  from prefect.logging.loggers import get_logger, get_run_logger
31
- from prefect.results import (
32
- BaseResult,
33
- R,
34
- ResultRecord,
35
- ResultRecordMetadata,
36
- ResultStore,
37
- )
38
31
  from prefect.utilities.annotations import BaseAnnotation
39
32
  from prefect.utilities.asyncutils import in_async_main_thread, sync_compatible
40
33
  from prefect.utilities.collections import ensure_iterable
41
34
 
35
+ if TYPE_CHECKING:
36
+ from prefect.results import (
37
+ R,
38
+ ResultStore,
39
+ )
40
+
42
41
  logger = get_logger("states")
43
42
 
44
43
 
@@ -50,11 +49,11 @@ logger = get_logger("states")
50
49
  help="Please ensure you are awaiting the call to `result()` when calling in an async context.",
51
50
  )
52
51
  def get_state_result(
53
- state: State[R],
52
+ state: "State[R]",
54
53
  raise_on_failure: bool = True,
55
54
  fetch: bool = True,
56
55
  retry_result_failure: bool = True,
57
- ) -> R:
56
+ ) -> "R":
58
57
  """
59
58
  Get the result from a state.
60
59
 
@@ -87,13 +86,18 @@ RESULT_READ_RETRY_DELAY = 0.25
87
86
 
88
87
 
89
88
  async def _get_state_result_data_with_retries(
90
- state: State[R], retry_result_failure: bool = True
91
- ) -> R:
89
+ state: "State[R]", retry_result_failure: bool = True
90
+ ) -> "R":
92
91
  # Results may be written asynchronously, possibly after their corresponding
93
92
  # state has been written and events have been emitted, so we should give some
94
93
  # grace here about missing results. The exception below could come in the form
95
94
  # of a missing file, a short read, or other types of errors depending on the
96
95
  # result storage backend.
96
+ from prefect.results import (
97
+ ResultRecord,
98
+ ResultRecordMetadata,
99
+ )
100
+
97
101
  if retry_result_failure is False:
98
102
  max_attempts = 1
99
103
  else:
@@ -121,11 +125,16 @@ async def _get_state_result_data_with_retries(
121
125
 
122
126
  @sync_compatible
123
127
  async def _get_state_result(
124
- state: State[R], raise_on_failure: bool, retry_result_failure: bool = True
125
- ) -> R:
128
+ state: "State[R]", raise_on_failure: bool, retry_result_failure: bool = True
129
+ ) -> "R":
126
130
  """
127
131
  Internal implementation for `get_state_result` without async backwards compatibility
128
132
  """
133
+ from prefect.results import (
134
+ ResultRecord,
135
+ ResultRecordMetadata,
136
+ )
137
+
129
138
  if state.is_paused():
130
139
  # Paused states are not truly terminal and do not have results associated with them
131
140
  raise PausedRun("Run is paused, its result is not available.", state=state)
@@ -140,7 +149,7 @@ async def _get_state_result(
140
149
  ):
141
150
  raise await get_state_exception(state)
142
151
 
143
- if isinstance(state.data, (BaseResult, ResultRecordMetadata)):
152
+ if isinstance(state.data, ResultRecordMetadata):
144
153
  result = await _get_state_result_data_with_retries(
145
154
  state, retry_result_failure=retry_result_failure
146
155
  )
@@ -182,7 +191,7 @@ def format_exception(exc: BaseException, tb: TracebackType = None) -> str:
182
191
 
183
192
  async def exception_to_crashed_state(
184
193
  exc: BaseException,
185
- result_store: Optional[ResultStore] = None,
194
+ result_store: Optional["ResultStore"] = None,
186
195
  ) -> State:
187
196
  """
188
197
  Takes an exception that occurs _outside_ of user code and converts it to a
@@ -234,7 +243,7 @@ async def exception_to_crashed_state(
234
243
 
235
244
  async def exception_to_failed_state(
236
245
  exc: Optional[BaseException] = None,
237
- result_store: Optional[ResultStore] = None,
246
+ result_store: Optional["ResultStore"] = None,
238
247
  write_result: bool = False,
239
248
  **kwargs,
240
249
  ) -> State:
@@ -286,12 +295,12 @@ async def exception_to_failed_state(
286
295
 
287
296
 
288
297
  async def return_value_to_state(
289
- retval: R,
290
- result_store: ResultStore,
298
+ retval: "R",
299
+ result_store: "ResultStore",
291
300
  key: Optional[str] = None,
292
301
  expiration: Optional[datetime.datetime] = None,
293
302
  write_result: bool = False,
294
- ) -> State[R]:
303
+ ) -> "State[R]":
295
304
  """
296
305
  Given a return value from a user's function, create a `State` the run should
297
306
  be placed in.
@@ -312,6 +321,11 @@ async def return_value_to_state(
312
321
  Callers should resolve all futures into states before passing return values to this
313
322
  function.
314
323
  """
324
+ from prefect.results import (
325
+ ResultRecord,
326
+ ResultRecordMetadata,
327
+ )
328
+
315
329
  try:
316
330
  local_logger = get_run_logger()
317
331
  except MissingContextError:
@@ -326,7 +340,7 @@ async def return_value_to_state(
326
340
  state = retval
327
341
  # Unless the user has already constructed a result explicitly, use the store
328
342
  # to update the data to the correct type
329
- if not isinstance(state.data, (BaseResult, ResultRecord, ResultRecordMetadata)):
343
+ if not isinstance(state.data, (ResultRecord, ResultRecordMetadata)):
330
344
  result_record = result_store.create_result_record(
331
345
  state.data,
332
346
  key=key,
@@ -402,7 +416,7 @@ async def return_value_to_state(
402
416
  data = retval
403
417
 
404
418
  # Otherwise, they just gave data and this is a completed retval
405
- if isinstance(data, (BaseResult, ResultRecord)):
419
+ if isinstance(data, ResultRecord):
406
420
  return Completed(data=data)
407
421
  else:
408
422
  result_record = result_store.create_result_record(
@@ -444,6 +458,10 @@ async def get_state_exception(state: State) -> BaseException:
444
458
  - `CrashedRun` if the state type is CRASHED.
445
459
  - `CancelledRun` if the state type is CANCELLED.
446
460
  """
461
+ from prefect.results import (
462
+ ResultRecord,
463
+ ResultRecordMetadata,
464
+ )
447
465
 
448
466
  if state.is_failed():
449
467
  wrapper = FailedRun
@@ -457,9 +475,7 @@ async def get_state_exception(state: State) -> BaseException:
457
475
  else:
458
476
  raise ValueError(f"Expected failed or crashed state got {state!r}.")
459
477
 
460
- if isinstance(state.data, BaseResult):
461
- result = await _get_state_result_data_with_retries(state)
462
- elif isinstance(state.data, ResultRecord):
478
+ if isinstance(state.data, ResultRecord):
463
479
  result = state.data.result
464
480
  elif isinstance(state.data, ResultRecordMetadata):
465
481
  record = await ResultRecord._from_metadata(state.data)
@@ -589,7 +605,7 @@ class StateGroup:
589
605
  return f"StateGroup<{self.counts_message()}>"
590
606
 
591
607
 
592
- def _traced(cls: Type[State[R]], **kwargs: Any) -> State[R]:
608
+ def _traced(cls: Type["State[R]"], **kwargs: Any) -> "State[R]":
593
609
  state_details = StateDetails.model_validate(kwargs.pop("state_details", {}))
594
610
 
595
611
  carrier = {}
@@ -600,10 +616,10 @@ def _traced(cls: Type[State[R]], **kwargs: Any) -> State[R]:
600
616
 
601
617
 
602
618
  def Scheduled(
603
- cls: Type[State[R]] = State,
619
+ cls: Type["State[R]"] = State,
604
620
  scheduled_time: Optional[datetime.datetime] = None,
605
621
  **kwargs: Any,
606
- ) -> State[R]:
622
+ ) -> "State[R]":
607
623
  """Convenience function for creating `Scheduled` states.
608
624
 
609
625
  Returns:
@@ -619,7 +635,7 @@ def Scheduled(
619
635
  return _traced(cls, type=StateType.SCHEDULED, state_details=state_details, **kwargs)
620
636
 
621
637
 
622
- def Completed(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
638
+ def Completed(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
623
639
  """Convenience function for creating `Completed` states.
624
640
 
625
641
  Returns:
@@ -629,7 +645,7 @@ def Completed(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
629
645
  return _traced(cls, type=StateType.COMPLETED, **kwargs)
630
646
 
631
647
 
632
- def Running(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
648
+ def Running(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
633
649
  """Convenience function for creating `Running` states.
634
650
 
635
651
  Returns:
@@ -638,7 +654,7 @@ def Running(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
638
654
  return _traced(cls, type=StateType.RUNNING, **kwargs)
639
655
 
640
656
 
641
- def Failed(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
657
+ def Failed(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
642
658
  """Convenience function for creating `Failed` states.
643
659
 
644
660
  Returns:
@@ -647,7 +663,7 @@ def Failed(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
647
663
  return _traced(cls, type=StateType.FAILED, **kwargs)
648
664
 
649
665
 
650
- def Crashed(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
666
+ def Crashed(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
651
667
  """Convenience function for creating `Crashed` states.
652
668
 
653
669
  Returns:
@@ -656,7 +672,7 @@ def Crashed(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
656
672
  return _traced(cls, type=StateType.CRASHED, **kwargs)
657
673
 
658
674
 
659
- def Cancelling(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
675
+ def Cancelling(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
660
676
  """Convenience function for creating `Cancelling` states.
661
677
 
662
678
  Returns:
@@ -665,7 +681,7 @@ def Cancelling(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
665
681
  return _traced(cls, type=StateType.CANCELLING, **kwargs)
666
682
 
667
683
 
668
- def Cancelled(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
684
+ def Cancelled(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
669
685
  """Convenience function for creating `Cancelled` states.
670
686
 
671
687
  Returns:
@@ -674,7 +690,7 @@ def Cancelled(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
674
690
  return _traced(cls, type=StateType.CANCELLED, **kwargs)
675
691
 
676
692
 
677
- def Pending(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
693
+ def Pending(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
678
694
  """Convenience function for creating `Pending` states.
679
695
 
680
696
  Returns:
@@ -684,13 +700,13 @@ def Pending(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
684
700
 
685
701
 
686
702
  def Paused(
687
- cls: Type[State[R]] = State,
703
+ cls: Type["State[R]"] = State,
688
704
  timeout_seconds: Optional[int] = None,
689
705
  pause_expiration_time: Optional[datetime.datetime] = None,
690
706
  reschedule: bool = False,
691
707
  pause_key: Optional[str] = None,
692
708
  **kwargs: Any,
693
- ) -> State[R]:
709
+ ) -> "State[R]":
694
710
  """Convenience function for creating `Paused` states.
695
711
 
696
712
  Returns:
@@ -720,7 +736,7 @@ def Paused(
720
736
 
721
737
 
722
738
  def Suspended(
723
- cls: Type[State[R]] = State,
739
+ cls: Type["State[R]"] = State,
724
740
  timeout_seconds: Optional[int] = None,
725
741
  pause_expiration_time: Optional[datetime.datetime] = None,
726
742
  pause_key: Optional[str] = None,
@@ -743,10 +759,10 @@ def Suspended(
743
759
 
744
760
 
745
761
  def AwaitingRetry(
746
- cls: Type[State[R]] = State,
762
+ cls: Type["State[R]"] = State,
747
763
  scheduled_time: Optional[datetime.datetime] = None,
748
764
  **kwargs: Any,
749
- ) -> State[R]:
765
+ ) -> "State[R]":
750
766
  """Convenience function for creating `AwaitingRetry` states.
751
767
 
752
768
  Returns:
@@ -758,10 +774,10 @@ def AwaitingRetry(
758
774
 
759
775
 
760
776
  def AwaitingConcurrencySlot(
761
- cls: Type[State[R]] = State,
777
+ cls: Type["State[R]"] = State,
762
778
  scheduled_time: Optional[datetime.datetime] = None,
763
779
  **kwargs: Any,
764
- ) -> State[R]:
780
+ ) -> "State[R]":
765
781
  """Convenience function for creating `AwaitingConcurrencySlot` states.
766
782
 
767
783
  Returns:
@@ -772,7 +788,7 @@ def AwaitingConcurrencySlot(
772
788
  )
773
789
 
774
790
 
775
- def Retrying(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
791
+ def Retrying(cls: Type["State[R]"] = State, **kwargs: Any) -> "State[R]":
776
792
  """Convenience function for creating `Retrying` states.
777
793
 
778
794
  Returns:
@@ -782,10 +798,10 @@ def Retrying(cls: Type[State[R]] = State, **kwargs: Any) -> State[R]:
782
798
 
783
799
 
784
800
  def Late(
785
- cls: Type[State[R]] = State,
801
+ cls: Type["State[R]"] = State,
786
802
  scheduled_time: Optional[datetime.datetime] = None,
787
803
  **kwargs: Any,
788
- ) -> State[R]:
804
+ ) -> "State[R]":
789
805
  """Convenience function for creating `Late` states.
790
806
 
791
807
  Returns: