prefect-client 2.19.4__py3-none-any.whl → 3.0.0rc2__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 (242) hide show
  1. prefect/__init__.py +8 -56
  2. prefect/_internal/compatibility/deprecated.py +6 -115
  3. prefect/_internal/compatibility/experimental.py +4 -79
  4. prefect/_internal/concurrency/api.py +0 -34
  5. prefect/_internal/concurrency/calls.py +0 -6
  6. prefect/_internal/concurrency/cancellation.py +0 -3
  7. prefect/_internal/concurrency/event_loop.py +0 -20
  8. prefect/_internal/concurrency/inspection.py +3 -3
  9. prefect/_internal/concurrency/threads.py +35 -0
  10. prefect/_internal/concurrency/waiters.py +0 -28
  11. prefect/_internal/pydantic/__init__.py +0 -45
  12. prefect/_internal/pydantic/v1_schema.py +21 -22
  13. prefect/_internal/pydantic/v2_schema.py +0 -2
  14. prefect/_internal/pydantic/v2_validated_func.py +18 -23
  15. prefect/_internal/schemas/bases.py +44 -177
  16. prefect/_internal/schemas/fields.py +1 -43
  17. prefect/_internal/schemas/validators.py +60 -158
  18. prefect/artifacts.py +161 -14
  19. prefect/automations.py +39 -4
  20. prefect/blocks/abstract.py +1 -1
  21. prefect/blocks/core.py +268 -148
  22. prefect/blocks/fields.py +2 -57
  23. prefect/blocks/kubernetes.py +8 -12
  24. prefect/blocks/notifications.py +40 -20
  25. prefect/blocks/redis.py +168 -0
  26. prefect/blocks/system.py +22 -11
  27. prefect/blocks/webhook.py +2 -9
  28. prefect/client/base.py +4 -4
  29. prefect/client/cloud.py +8 -13
  30. prefect/client/orchestration.py +362 -340
  31. prefect/client/schemas/actions.py +92 -86
  32. prefect/client/schemas/filters.py +20 -40
  33. prefect/client/schemas/objects.py +158 -152
  34. prefect/client/schemas/responses.py +16 -24
  35. prefect/client/schemas/schedules.py +47 -35
  36. prefect/client/subscriptions.py +2 -2
  37. prefect/client/utilities.py +5 -2
  38. prefect/concurrency/asyncio.py +4 -2
  39. prefect/concurrency/events.py +1 -1
  40. prefect/concurrency/services.py +7 -4
  41. prefect/context.py +195 -27
  42. prefect/deployments/__init__.py +5 -6
  43. prefect/deployments/base.py +7 -5
  44. prefect/deployments/flow_runs.py +185 -0
  45. prefect/deployments/runner.py +50 -45
  46. prefect/deployments/schedules.py +28 -23
  47. prefect/deployments/steps/__init__.py +0 -1
  48. prefect/deployments/steps/core.py +1 -0
  49. prefect/deployments/steps/pull.py +7 -21
  50. prefect/engine.py +12 -2422
  51. prefect/events/actions.py +17 -23
  52. prefect/events/cli/automations.py +19 -6
  53. prefect/events/clients.py +14 -37
  54. prefect/events/filters.py +14 -18
  55. prefect/events/related.py +2 -2
  56. prefect/events/schemas/__init__.py +0 -5
  57. prefect/events/schemas/automations.py +55 -46
  58. prefect/events/schemas/deployment_triggers.py +7 -197
  59. prefect/events/schemas/events.py +36 -65
  60. prefect/events/schemas/labelling.py +10 -14
  61. prefect/events/utilities.py +2 -3
  62. prefect/events/worker.py +2 -3
  63. prefect/filesystems.py +6 -517
  64. prefect/{new_flow_engine.py → flow_engine.py} +315 -74
  65. prefect/flow_runs.py +379 -7
  66. prefect/flows.py +248 -165
  67. prefect/futures.py +187 -345
  68. prefect/infrastructure/__init__.py +0 -27
  69. prefect/infrastructure/provisioners/__init__.py +5 -3
  70. prefect/infrastructure/provisioners/cloud_run.py +11 -6
  71. prefect/infrastructure/provisioners/container_instance.py +11 -7
  72. prefect/infrastructure/provisioners/ecs.py +6 -4
  73. prefect/infrastructure/provisioners/modal.py +8 -5
  74. prefect/input/actions.py +2 -4
  75. prefect/input/run_input.py +9 -9
  76. prefect/logging/formatters.py +0 -2
  77. prefect/logging/handlers.py +3 -11
  78. prefect/logging/loggers.py +2 -2
  79. prefect/manifests.py +2 -1
  80. prefect/records/__init__.py +1 -0
  81. prefect/records/cache_policies.py +179 -0
  82. prefect/records/result_store.py +42 -0
  83. prefect/records/store.py +9 -0
  84. prefect/results.py +43 -39
  85. prefect/runner/runner.py +9 -9
  86. prefect/runner/server.py +6 -10
  87. prefect/runner/storage.py +3 -8
  88. prefect/runner/submit.py +2 -2
  89. prefect/runner/utils.py +2 -2
  90. prefect/serializers.py +24 -35
  91. prefect/server/api/collections_data/views/aggregate-worker-metadata.json +5 -14
  92. prefect/settings.py +76 -136
  93. prefect/states.py +22 -50
  94. prefect/task_engine.py +666 -56
  95. prefect/task_runners.py +272 -300
  96. prefect/task_runs.py +203 -0
  97. prefect/{task_server.py → task_worker.py} +89 -60
  98. prefect/tasks.py +358 -341
  99. prefect/transactions.py +224 -0
  100. prefect/types/__init__.py +61 -82
  101. prefect/utilities/asyncutils.py +195 -136
  102. prefect/utilities/callables.py +121 -41
  103. prefect/utilities/collections.py +23 -38
  104. prefect/utilities/dispatch.py +11 -3
  105. prefect/utilities/dockerutils.py +4 -0
  106. prefect/utilities/engine.py +140 -20
  107. prefect/utilities/importtools.py +26 -27
  108. prefect/utilities/pydantic.py +128 -38
  109. prefect/utilities/schema_tools/hydration.py +5 -1
  110. prefect/utilities/templating.py +12 -2
  111. prefect/variables.py +84 -62
  112. prefect/workers/__init__.py +0 -1
  113. prefect/workers/base.py +26 -18
  114. prefect/workers/process.py +3 -8
  115. prefect/workers/server.py +2 -2
  116. {prefect_client-2.19.4.dist-info → prefect_client-3.0.0rc2.dist-info}/METADATA +23 -21
  117. prefect_client-3.0.0rc2.dist-info/RECORD +179 -0
  118. prefect/_internal/pydantic/_base_model.py +0 -51
  119. prefect/_internal/pydantic/_compat.py +0 -82
  120. prefect/_internal/pydantic/_flags.py +0 -20
  121. prefect/_internal/pydantic/_types.py +0 -8
  122. prefect/_internal/pydantic/utilities/__init__.py +0 -0
  123. prefect/_internal/pydantic/utilities/config_dict.py +0 -72
  124. prefect/_internal/pydantic/utilities/field_validator.py +0 -150
  125. prefect/_internal/pydantic/utilities/model_construct.py +0 -56
  126. prefect/_internal/pydantic/utilities/model_copy.py +0 -55
  127. prefect/_internal/pydantic/utilities/model_dump.py +0 -136
  128. prefect/_internal/pydantic/utilities/model_dump_json.py +0 -112
  129. prefect/_internal/pydantic/utilities/model_fields.py +0 -50
  130. prefect/_internal/pydantic/utilities/model_fields_set.py +0 -29
  131. prefect/_internal/pydantic/utilities/model_json_schema.py +0 -82
  132. prefect/_internal/pydantic/utilities/model_rebuild.py +0 -80
  133. prefect/_internal/pydantic/utilities/model_validate.py +0 -75
  134. prefect/_internal/pydantic/utilities/model_validate_json.py +0 -68
  135. prefect/_internal/pydantic/utilities/model_validator.py +0 -87
  136. prefect/_internal/pydantic/utilities/type_adapter.py +0 -71
  137. prefect/_vendor/__init__.py +0 -0
  138. prefect/_vendor/fastapi/__init__.py +0 -25
  139. prefect/_vendor/fastapi/applications.py +0 -946
  140. prefect/_vendor/fastapi/background.py +0 -3
  141. prefect/_vendor/fastapi/concurrency.py +0 -44
  142. prefect/_vendor/fastapi/datastructures.py +0 -58
  143. prefect/_vendor/fastapi/dependencies/__init__.py +0 -0
  144. prefect/_vendor/fastapi/dependencies/models.py +0 -64
  145. prefect/_vendor/fastapi/dependencies/utils.py +0 -877
  146. prefect/_vendor/fastapi/encoders.py +0 -177
  147. prefect/_vendor/fastapi/exception_handlers.py +0 -40
  148. prefect/_vendor/fastapi/exceptions.py +0 -46
  149. prefect/_vendor/fastapi/logger.py +0 -3
  150. prefect/_vendor/fastapi/middleware/__init__.py +0 -1
  151. prefect/_vendor/fastapi/middleware/asyncexitstack.py +0 -25
  152. prefect/_vendor/fastapi/middleware/cors.py +0 -3
  153. prefect/_vendor/fastapi/middleware/gzip.py +0 -3
  154. prefect/_vendor/fastapi/middleware/httpsredirect.py +0 -3
  155. prefect/_vendor/fastapi/middleware/trustedhost.py +0 -3
  156. prefect/_vendor/fastapi/middleware/wsgi.py +0 -3
  157. prefect/_vendor/fastapi/openapi/__init__.py +0 -0
  158. prefect/_vendor/fastapi/openapi/constants.py +0 -2
  159. prefect/_vendor/fastapi/openapi/docs.py +0 -203
  160. prefect/_vendor/fastapi/openapi/models.py +0 -480
  161. prefect/_vendor/fastapi/openapi/utils.py +0 -485
  162. prefect/_vendor/fastapi/param_functions.py +0 -340
  163. prefect/_vendor/fastapi/params.py +0 -453
  164. prefect/_vendor/fastapi/requests.py +0 -4
  165. prefect/_vendor/fastapi/responses.py +0 -40
  166. prefect/_vendor/fastapi/routing.py +0 -1331
  167. prefect/_vendor/fastapi/security/__init__.py +0 -15
  168. prefect/_vendor/fastapi/security/api_key.py +0 -98
  169. prefect/_vendor/fastapi/security/base.py +0 -6
  170. prefect/_vendor/fastapi/security/http.py +0 -172
  171. prefect/_vendor/fastapi/security/oauth2.py +0 -227
  172. prefect/_vendor/fastapi/security/open_id_connect_url.py +0 -34
  173. prefect/_vendor/fastapi/security/utils.py +0 -10
  174. prefect/_vendor/fastapi/staticfiles.py +0 -1
  175. prefect/_vendor/fastapi/templating.py +0 -3
  176. prefect/_vendor/fastapi/testclient.py +0 -1
  177. prefect/_vendor/fastapi/types.py +0 -3
  178. prefect/_vendor/fastapi/utils.py +0 -235
  179. prefect/_vendor/fastapi/websockets.py +0 -7
  180. prefect/_vendor/starlette/__init__.py +0 -1
  181. prefect/_vendor/starlette/_compat.py +0 -28
  182. prefect/_vendor/starlette/_exception_handler.py +0 -80
  183. prefect/_vendor/starlette/_utils.py +0 -88
  184. prefect/_vendor/starlette/applications.py +0 -261
  185. prefect/_vendor/starlette/authentication.py +0 -159
  186. prefect/_vendor/starlette/background.py +0 -43
  187. prefect/_vendor/starlette/concurrency.py +0 -59
  188. prefect/_vendor/starlette/config.py +0 -151
  189. prefect/_vendor/starlette/convertors.py +0 -87
  190. prefect/_vendor/starlette/datastructures.py +0 -707
  191. prefect/_vendor/starlette/endpoints.py +0 -130
  192. prefect/_vendor/starlette/exceptions.py +0 -60
  193. prefect/_vendor/starlette/formparsers.py +0 -276
  194. prefect/_vendor/starlette/middleware/__init__.py +0 -17
  195. prefect/_vendor/starlette/middleware/authentication.py +0 -52
  196. prefect/_vendor/starlette/middleware/base.py +0 -220
  197. prefect/_vendor/starlette/middleware/cors.py +0 -176
  198. prefect/_vendor/starlette/middleware/errors.py +0 -265
  199. prefect/_vendor/starlette/middleware/exceptions.py +0 -74
  200. prefect/_vendor/starlette/middleware/gzip.py +0 -113
  201. prefect/_vendor/starlette/middleware/httpsredirect.py +0 -19
  202. prefect/_vendor/starlette/middleware/sessions.py +0 -82
  203. prefect/_vendor/starlette/middleware/trustedhost.py +0 -64
  204. prefect/_vendor/starlette/middleware/wsgi.py +0 -147
  205. prefect/_vendor/starlette/requests.py +0 -328
  206. prefect/_vendor/starlette/responses.py +0 -347
  207. prefect/_vendor/starlette/routing.py +0 -933
  208. prefect/_vendor/starlette/schemas.py +0 -154
  209. prefect/_vendor/starlette/staticfiles.py +0 -248
  210. prefect/_vendor/starlette/status.py +0 -199
  211. prefect/_vendor/starlette/templating.py +0 -231
  212. prefect/_vendor/starlette/testclient.py +0 -804
  213. prefect/_vendor/starlette/types.py +0 -30
  214. prefect/_vendor/starlette/websockets.py +0 -193
  215. prefect/agent.py +0 -698
  216. prefect/deployments/deployments.py +0 -1042
  217. prefect/deprecated/__init__.py +0 -0
  218. prefect/deprecated/data_documents.py +0 -350
  219. prefect/deprecated/packaging/__init__.py +0 -12
  220. prefect/deprecated/packaging/base.py +0 -96
  221. prefect/deprecated/packaging/docker.py +0 -146
  222. prefect/deprecated/packaging/file.py +0 -92
  223. prefect/deprecated/packaging/orion.py +0 -80
  224. prefect/deprecated/packaging/serializers.py +0 -171
  225. prefect/events/instrument.py +0 -135
  226. prefect/infrastructure/base.py +0 -323
  227. prefect/infrastructure/container.py +0 -818
  228. prefect/infrastructure/kubernetes.py +0 -920
  229. prefect/infrastructure/process.py +0 -289
  230. prefect/new_task_engine.py +0 -423
  231. prefect/pydantic/__init__.py +0 -76
  232. prefect/pydantic/main.py +0 -39
  233. prefect/software/__init__.py +0 -2
  234. prefect/software/base.py +0 -50
  235. prefect/software/conda.py +0 -199
  236. prefect/software/pip.py +0 -122
  237. prefect/software/python.py +0 -52
  238. prefect/workers/block.py +0 -218
  239. prefect_client-2.19.4.dist-info/RECORD +0 -292
  240. {prefect_client-2.19.4.dist-info → prefect_client-3.0.0rc2.dist-info}/LICENSE +0 -0
  241. {prefect_client-2.19.4.dist-info → prefect_client-3.0.0rc2.dist-info}/WHEEL +0 -0
  242. {prefect_client-2.19.4.dist-info → prefect_client-3.0.0rc2.dist-info}/top_level.txt +0 -0
prefect/settings.py CHANGED
@@ -65,36 +65,22 @@ from typing import (
65
65
  )
66
66
  from urllib.parse import urlparse
67
67
 
68
+ import pydantic
68
69
  import toml
69
-
70
- from prefect._internal.pydantic import HAS_PYDANTIC_V2
71
- from prefect._internal.schemas.validators import validate_settings
72
-
73
- if HAS_PYDANTIC_V2:
74
- from pydantic.v1 import (
75
- BaseModel,
76
- BaseSettings,
77
- Field,
78
- create_model,
79
- fields,
80
- root_validator,
81
- validator,
82
- )
83
- else:
84
- from pydantic import (
85
- BaseModel,
86
- BaseSettings,
87
- Field,
88
- create_model,
89
- fields,
90
- root_validator,
91
- validator,
92
- )
93
-
70
+ from pydantic import (
71
+ BaseModel,
72
+ ConfigDict,
73
+ Field,
74
+ create_model,
75
+ field_validator,
76
+ fields,
77
+ model_validator,
78
+ )
79
+ from pydantic_settings import BaseSettings, SettingsConfigDict
94
80
  from typing_extensions import Literal
95
81
 
96
82
  from prefect._internal.compatibility.deprecated import generate_deprecation_message
97
- from prefect._internal.pydantic import HAS_PYDANTIC_V2
83
+ from prefect._internal.schemas.validators import validate_settings
98
84
  from prefect.exceptions import MissingProfileError
99
85
  from prefect.utilities.names import OBFUSCATED_PREFIX, obfuscate
100
86
  from prefect.utilities.pydantic import add_cloudpickle_reduction
@@ -104,13 +90,19 @@ T = TypeVar("T")
104
90
 
105
91
  DEFAULT_PROFILES_PATH = Path(__file__).parent.joinpath("profiles.toml")
106
92
 
93
+ # When we remove the experimental settings we also want to add them to the set of REMOVED_EXPERIMENTAL_FLAGS.
94
+ # The reason for this is removing the settings entirely causes the CLI to crash for anyone who has them in one or more of their profiles.
95
+ # Adding them to REMOVED_EXPERIMENTAL_FLAGS will make it so that the user is warned about it and they have time to take action.
107
96
  REMOVED_EXPERIMENTAL_FLAGS = {
108
97
  "PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_SCHEDULING_UI",
109
98
  "PREFECT_EXPERIMENTAL_ENABLE_ENHANCED_DEPLOYMENT_PARAMETERS",
110
99
  "PREFECT_EXPERIMENTAL_ENABLE_EVENTS_CLIENT",
100
+ "PREFECT_EXPERIMENTAL_ENABLE_EVENTS",
101
+ "PREFECT_EXPERIMENTAL_EVENTS",
111
102
  "PREFECT_EXPERIMENTAL_WARN_EVENTS_CLIENT",
112
103
  "PREFECT_EXPERIMENTAL_ENABLE_FLOW_RUN_INFRA_OVERRIDES",
113
104
  "PREFECT_EXPERIMENTAL_WARN_FLOW_RUN_INFRA_OVERRIDES",
105
+ "PREFECT_EXPERIMENTAL_ENABLE_WORK_POOLS",
114
106
  }
115
107
 
116
108
 
@@ -245,7 +237,7 @@ class Setting(Generic[T]):
245
237
  )
246
238
 
247
239
  def __repr__(self) -> str:
248
- return f"<{self.name}: {self.type.__name__}>"
240
+ return f"<{self.name}: {self.type!r}>"
249
241
 
250
242
  def __bool__(self) -> bool:
251
243
  """
@@ -386,21 +378,6 @@ def warn_on_database_password_value_without_usage(values):
386
378
  return values
387
379
 
388
380
 
389
- def check_for_deprecated_cloud_url(settings, value):
390
- deprecated_value = PREFECT_CLOUD_URL.value_from(settings, bypass_callback=True)
391
- if deprecated_value is not None:
392
- warnings.warn(
393
- (
394
- "`PREFECT_CLOUD_URL` is set and will be used instead of"
395
- " `PREFECT_CLOUD_API_URL` for backwards compatibility."
396
- " `PREFECT_CLOUD_URL` is deprecated, set `PREFECT_CLOUD_API_URL`"
397
- " instead."
398
- ),
399
- DeprecationWarning,
400
- )
401
- return deprecated_value or value
402
-
403
-
404
381
  def warn_on_misconfigured_api_url(values):
405
382
  """
406
383
  Validator for settings warning if the API URL is misconfigured.
@@ -610,7 +587,7 @@ This is recommended only during development, e.g. when using self-signed certifi
610
587
  """
611
588
 
612
589
  PREFECT_API_SSL_CERT_FILE = Setting(
613
- str,
590
+ Optional[str],
614
591
  default=os.environ.get("SSL_CERT_FILE"),
615
592
  )
616
593
  """
@@ -620,7 +597,7 @@ If left unset, the setting will default to the value provided by the `SSL_CERT_F
620
597
  """
621
598
 
622
599
  PREFECT_API_URL = Setting(
623
- str,
600
+ Optional[str],
624
601
  default=None,
625
602
  )
626
603
  """
@@ -639,7 +616,7 @@ we would like to silence this warning so we will set it to `FALSE`.
639
616
  """
640
617
 
641
618
  PREFECT_API_KEY = Setting(
642
- str,
619
+ Optional[str],
643
620
  default=None,
644
621
  is_secret=True,
645
622
  )
@@ -702,22 +679,10 @@ Defaults to `True`, ensuring CSRF protection is enabled by default.
702
679
  PREFECT_CLOUD_API_URL = Setting(
703
680
  str,
704
681
  default="https://api.prefect.cloud/api",
705
- value_callback=check_for_deprecated_cloud_url,
706
682
  )
707
683
  """API URL for Prefect Cloud. Used for authentication."""
708
684
 
709
685
 
710
- PREFECT_CLOUD_URL = Setting(
711
- str,
712
- default=None,
713
- deprecated=True,
714
- deprecated_start_date="Dec 2022",
715
- deprecated_help="Use `PREFECT_CLOUD_API_URL` instead.",
716
- )
717
- """
718
- DEPRECATED: Use `PREFECT_CLOUD_API_URL` instead.
719
- """
720
-
721
686
  PREFECT_UI_URL = Setting(
722
687
  Optional[str],
723
688
  default=None,
@@ -732,7 +697,7 @@ When using an ephemeral server, this will be `None`.
732
697
 
733
698
 
734
699
  PREFECT_CLOUD_UI_URL = Setting(
735
- str,
700
+ Optional[str],
736
701
  default=None,
737
702
  value_callback=default_cloud_ui_url,
738
703
  )
@@ -946,7 +911,7 @@ The following options are available:
946
911
  """
947
912
 
948
913
  PREFECT_SQLALCHEMY_POOL_SIZE = Setting(
949
- int,
914
+ Optional[int],
950
915
  default=None,
951
916
  )
952
917
  """
@@ -954,7 +919,7 @@ Controls connection pool size when using a PostgreSQL database with the Prefect
954
919
  """
955
920
 
956
921
  PREFECT_SQLALCHEMY_MAX_OVERFLOW = Setting(
957
- int,
922
+ Optional[int],
958
923
  default=None,
959
924
  )
960
925
  """
@@ -1040,7 +1005,7 @@ registered.
1040
1005
  """
1041
1006
 
1042
1007
  PREFECT_API_DATABASE_PASSWORD = Setting(
1043
- str,
1008
+ Optional[str],
1044
1009
  default=None,
1045
1010
  is_secret=True,
1046
1011
  )
@@ -1051,7 +1016,7 @@ To use this setting, you must include it in your connection URL.
1051
1016
  """
1052
1017
 
1053
1018
  PREFECT_API_DATABASE_CONNECTION_URL = Setting(
1054
- str,
1019
+ Optional[str],
1055
1020
  default=None,
1056
1021
  value_callback=default_database_connection_url,
1057
1022
  is_secret=True,
@@ -1243,6 +1208,9 @@ PREFECT_API_SERVICES_FOREMAN_WORK_QUEUE_LAST_POLLED_TIMEOUT_SECONDS = Setting(
1243
1208
  """The number of seconds before a work queue is marked as not ready if it has not been
1244
1209
  polled."""
1245
1210
 
1211
+ PREFECT_API_LOG_RETRYABLE_ERRORS = Setting(bool, default=False)
1212
+ """If `True`, log retryable errors in the API and it's services."""
1213
+
1246
1214
 
1247
1215
  PREFECT_API_DEFAULT_LIMIT = Setting(
1248
1216
  int,
@@ -1313,7 +1281,7 @@ PREFECT_UI_ENABLED = Setting(
1313
1281
  """Whether or not to serve the Prefect UI."""
1314
1282
 
1315
1283
  PREFECT_UI_API_URL = Setting(
1316
- str,
1284
+ Optional[str],
1317
1285
  default=None,
1318
1286
  value_callback=default_ui_api_url,
1319
1287
  )
@@ -1401,16 +1369,6 @@ PREFECT_EXPERIMENTAL_ENABLE_STATES_ON_FLOW_RUN_GRAPH = Setting(bool, default=Tru
1401
1369
  Whether or not to enable flow run states on the flow run graph.
1402
1370
  """
1403
1371
 
1404
- PREFECT_EXPERIMENTAL_ENABLE_WORK_POOLS = Setting(bool, default=True)
1405
- """
1406
- Whether or not to enable experimental Prefect work pools.
1407
- """
1408
-
1409
- PREFECT_EXPERIMENTAL_WARN_WORK_POOLS = Setting(bool, default=False)
1410
- """
1411
- Whether or not to warn when experimental Prefect work pools are used.
1412
- """
1413
-
1414
1372
  PREFECT_EXPERIMENTAL_ENABLE_WORKERS = Setting(bool, default=True)
1415
1373
  """
1416
1374
  Whether or not to enable experimental Prefect workers.
@@ -1459,13 +1417,6 @@ Whether or not to enable flow run input.
1459
1417
 
1460
1418
  # Prefect Events feature flags
1461
1419
 
1462
- PREFECT_EXPERIMENTAL_EVENTS = Setting(bool, default=False)
1463
- """
1464
- Whether to enable Prefect's server-side event features. Note that Prefect Cloud clients
1465
- will always emit events during flow and task runs regardless of this setting.
1466
- """
1467
-
1468
-
1469
1420
  PREFECT_RUNNER_PROCESS_LIMIT = Setting(int, default=5)
1470
1421
  """
1471
1422
  Maximum number of processes a runner will execute in parallel.
@@ -1538,6 +1489,11 @@ PREFECT_WORKER_WEBSERVER_PORT = Setting(
1538
1489
  The port the worker's webserver should bind to.
1539
1490
  """
1540
1491
 
1492
+ PREFECT_API_SERVICES_TASK_SCHEDULING_ENABLED = Setting(bool, default=True)
1493
+ """
1494
+ Whether or not to start the task scheduling service in the server application.
1495
+ """
1496
+
1541
1497
  PREFECT_TASK_SCHEDULING_DEFAULT_STORAGE_BLOCK = Setting(
1542
1498
  str,
1543
1499
  default="local-file-system/prefect-task-scheduling",
@@ -1574,9 +1530,9 @@ PREFECT_TASK_SCHEDULING_PENDING_TASK_TIMEOUT = Setting(
1574
1530
  default=timedelta(seconds=30),
1575
1531
  )
1576
1532
  """
1577
- How long before a PENDING task are made available to another task server. In practice,
1578
- a task server should move a task from PENDING to RUNNING very quickly, so runs stuck in
1579
- PENDING for a while is a sign that the task server may have crashed.
1533
+ How long before a PENDING task are made available to another task worker. In practice,
1534
+ a task worker should move a task from PENDING to RUNNING very quickly, so runs stuck in
1535
+ PENDING for a while is a sign that the task worker may have crashed.
1580
1536
  """
1581
1537
 
1582
1538
  PREFECT_EXPERIMENTAL_ENABLE_EXTRA_RUNNER_ENDPOINTS = Setting(bool, default=False)
@@ -1604,42 +1560,33 @@ PREFECT_EXPERIMENTAL_WARN_WORKSPACE_DASHBOARD = Setting(bool, default=False)
1604
1560
  Whether or not to warn when the experimental workspace dashboard is enabled.
1605
1561
  """
1606
1562
 
1607
- PREFECT_EXPERIMENTAL_ENABLE_TASK_SCHEDULING = Setting(bool, default=False)
1608
- """
1609
- Whether or not to enable experimental task scheduling.
1610
- """
1611
-
1612
1563
  PREFECT_EXPERIMENTAL_ENABLE_WORK_QUEUE_STATUS = Setting(bool, default=True)
1613
1564
  """
1614
1565
  Whether or not to enable experimental work queue status in-place of work queue health.
1615
1566
  """
1616
1567
 
1617
- PREFECT_EXPERIMENTAL_ENABLE_NEW_ENGINE = Setting(bool, default=False)
1618
- """
1619
- Whether or not to enable experimental new engine.
1620
- """
1621
-
1622
1568
  PREFECT_EXPERIMENTAL_DISABLE_SYNC_COMPAT = Setting(bool, default=False)
1623
1569
  """
1624
1570
  Whether or not to disable the sync_compatible decorator utility.
1625
1571
  """
1626
1572
 
1573
+ PREFECT_EXPERIMENTAL_ENABLE_SCHEDULE_CONCURRENCY = Setting(bool, default=False)
1627
1574
 
1628
1575
  # Defaults -----------------------------------------------------------------------------
1629
1576
 
1630
1577
  PREFECT_DEFAULT_RESULT_STORAGE_BLOCK = Setting(
1631
- str,
1578
+ Optional[str],
1632
1579
  default=None,
1633
1580
  )
1634
1581
  """The `block-type/block-document` slug of a block to use as the default result storage."""
1635
1582
 
1636
- PREFECT_DEFAULT_WORK_POOL_NAME = Setting(str, default=None)
1583
+ PREFECT_DEFAULT_WORK_POOL_NAME = Setting(Optional[str], default=None)
1637
1584
  """
1638
1585
  The default work pool to deploy to.
1639
1586
  """
1640
1587
 
1641
1588
  PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE = Setting(
1642
- str,
1589
+ Optional[str],
1643
1590
  default=None,
1644
1591
  )
1645
1592
  """
@@ -1659,7 +1606,7 @@ Defaults to the root path.
1659
1606
  """
1660
1607
 
1661
1608
  PREFECT_UI_STATIC_DIRECTORY = Setting(
1662
- str,
1609
+ Optional[str],
1663
1610
  default=None,
1664
1611
  )
1665
1612
  """
@@ -1756,16 +1703,6 @@ How long to cache related resource data for emitting server-side vents
1756
1703
  """
1757
1704
 
1758
1705
 
1759
- def automation_settings_enabled() -> bool:
1760
- """
1761
- Whether or not automations are enabled.
1762
- """
1763
- return (
1764
- PREFECT_EXPERIMENTAL_EVENTS.value()
1765
- and PREFECT_API_SERVICES_TRIGGERS_ENABLED.value()
1766
- )
1767
-
1768
-
1769
1706
  # Deprecated settings ------------------------------------------------------------------
1770
1707
 
1771
1708
 
@@ -1783,10 +1720,14 @@ for __name, __setting in SETTING_VARIABLES.items():
1783
1720
 
1784
1721
  # Dynamically create a pydantic model that includes all of our settings
1785
1722
 
1786
- SettingsFieldsMixin = create_model(
1723
+
1724
+ class PrefectBaseSettings(BaseSettings):
1725
+ model_config = SettingsConfigDict(extra="ignore")
1726
+
1727
+
1728
+ SettingsFieldsMixin: Type[BaseSettings] = create_model(
1787
1729
  "SettingsFieldsMixin",
1788
- # Inheriting from `BaseSettings` provides environment variable loading
1789
- __base__=BaseSettings,
1730
+ __base__=PrefectBaseSettings, # Inheriting from `BaseSettings` provides environment variable loading
1790
1731
  **{
1791
1732
  setting.name: (setting.type, setting.field)
1792
1733
  for setting in SETTING_VARIABLES.values()
@@ -1828,32 +1769,33 @@ class Settings(SettingsFieldsMixin):
1828
1769
  value = setting.value_callback(self, value)
1829
1770
  return value
1830
1771
 
1831
- @validator(PREFECT_LOGGING_LEVEL.name, PREFECT_LOGGING_SERVER_LEVEL.name)
1772
+ @field_validator(PREFECT_LOGGING_LEVEL.name, PREFECT_LOGGING_SERVER_LEVEL.name)
1832
1773
  def check_valid_log_level(cls, value):
1833
1774
  if isinstance(value, str):
1834
1775
  value = value.upper()
1835
1776
  logging._checkLevel(value)
1836
1777
  return value
1837
1778
 
1838
- @root_validator
1839
- def post_root_validators(cls, values):
1779
+ @model_validator(mode="after")
1780
+ def emit_warnings(self):
1840
1781
  """
1841
1782
  Add root validation functions for settings here.
1842
1783
  """
1843
1784
  # TODO: We could probably register these dynamically but this is the simpler
1844
1785
  # approach for now. We can explore more interesting validation features
1845
1786
  # in the future.
1787
+ values = self.model_dump()
1846
1788
  values = max_log_size_smaller_than_batch_size(values)
1847
1789
  values = warn_on_database_password_value_without_usage(values)
1848
1790
  if not values["PREFECT_SILENCE_API_URL_MISCONFIGURATION"]:
1849
1791
  values = warn_on_misconfigured_api_url(values)
1850
- return values
1792
+ return self
1851
1793
 
1852
1794
  def copy_with_update(
1853
1795
  self,
1854
- updates: Mapping[Setting, Any] = None,
1855
- set_defaults: Mapping[Setting, Any] = None,
1856
- restore_defaults: Iterable[Setting] = None,
1796
+ updates: Optional[Mapping[Setting, Any]] = None,
1797
+ set_defaults: Optional[Mapping[Setting, Any]] = None,
1798
+ restore_defaults: Optional[Iterable[Setting]] = None,
1857
1799
  ) -> "Settings":
1858
1800
  """
1859
1801
  Create a new `Settings` object with validation.
@@ -1876,7 +1818,7 @@ class Settings(SettingsFieldsMixin):
1876
1818
  return self.__class__(
1877
1819
  **{
1878
1820
  **{setting.name: value for setting, value in set_defaults.items()},
1879
- **self.dict(exclude_unset=True, exclude=restore_defaults_names),
1821
+ **self.model_dump(exclude_unset=True, exclude=restore_defaults_names),
1880
1822
  **{setting.name: value for setting, value in updates.items()},
1881
1823
  }
1882
1824
  )
@@ -1885,7 +1827,7 @@ class Settings(SettingsFieldsMixin):
1885
1827
  """
1886
1828
  Returns a copy of this settings object with secret setting values obfuscated.
1887
1829
  """
1888
- settings = self.copy(
1830
+ settings = self.model_copy(
1889
1831
  update={
1890
1832
  setting.name: obfuscate(self.value_of(setting))
1891
1833
  for setting in SETTING_VARIABLES.values()
@@ -1896,7 +1838,11 @@ class Settings(SettingsFieldsMixin):
1896
1838
  )
1897
1839
  # Ensure that settings that have not been marked as "set" before are still so
1898
1840
  # after we have updated their value above
1899
- settings.__fields_set__.intersection_update(self.__fields_set__)
1841
+ with warnings.catch_warnings():
1842
+ warnings.simplefilter(
1843
+ "ignore", category=pydantic.warnings.PydanticDeprecatedSince20
1844
+ )
1845
+ settings.__fields_set__.intersection_update(self.__fields_set__)
1900
1846
  return settings
1901
1847
 
1902
1848
  def hash_key(self) -> str:
@@ -1908,7 +1854,7 @@ class Settings(SettingsFieldsMixin):
1908
1854
  return str(hash(tuple((key, value) for key, value in env_variables.items())))
1909
1855
 
1910
1856
  def to_environment_variables(
1911
- self, include: Iterable[Setting] = None, exclude_unset: bool = False
1857
+ self, include: Optional[Iterable[Setting]] = None, exclude_unset: bool = False
1912
1858
  ) -> Dict[str, str]:
1913
1859
  """
1914
1860
  Convert the settings object to environment variables.
@@ -1932,7 +1878,7 @@ class Settings(SettingsFieldsMixin):
1932
1878
  set_keys = {
1933
1879
  # Collect all of the "set" keys and cast to `Setting` objects
1934
1880
  SETTING_VARIABLES[key]
1935
- for key in self.dict(exclude_unset=True)
1881
+ for key in self.model_dump(exclude_unset=True)
1936
1882
  }
1937
1883
  include.intersection_update(set_keys)
1938
1884
 
@@ -1943,23 +1889,19 @@ class Settings(SettingsFieldsMixin):
1943
1889
  "Invalid type {type(key).__name__!r} for key in `include`."
1944
1890
  )
1945
1891
 
1946
- env = {
1947
- # Use `getattr` instead of `value_of` to avoid value callback resolution
1948
- key: getattr(self, key)
1949
- for key, setting in SETTING_VARIABLES.items()
1950
- if setting in include
1951
- }
1892
+ env: dict[str, Any] = self.model_dump(
1893
+ mode="json", include={s.name for s in include}
1894
+ )
1952
1895
 
1953
1896
  # Cast to strings and drop null values
1954
1897
  return {key: str(value) for key, value in env.items() if value is not None}
1955
1898
 
1956
- class Config:
1957
- frozen = True
1899
+ model_config = ConfigDict(frozen=True)
1958
1900
 
1959
1901
 
1960
1902
  # Functions to instantiate `Settings` instances
1961
1903
 
1962
- _DEFAULTS_CACHE: Settings = None
1904
+ _DEFAULTS_CACHE: Optional[Settings] = None
1963
1905
  _FROM_ENV_CACHE: Dict[int, Settings] = {}
1964
1906
 
1965
1907
 
@@ -2066,9 +2008,10 @@ class Profile(BaseModel):
2066
2008
 
2067
2009
  name: str
2068
2010
  settings: Dict[Setting, Any] = Field(default_factory=dict)
2069
- source: Optional[Path]
2011
+ source: Optional[Path] = None
2012
+ model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True)
2070
2013
 
2071
- @validator("settings", pre=True)
2014
+ @field_validator("settings", mode="before")
2072
2015
  def map_names_to_settings(cls, value):
2073
2016
  return validate_settings(value)
2074
2017
 
@@ -2105,9 +2048,6 @@ class Profile(BaseModel):
2105
2048
  changed.append((setting, setting.deprecated_renamed_to))
2106
2049
  return changed
2107
2050
 
2108
- class Config:
2109
- arbitrary_types_allowed = True
2110
-
2111
2051
 
2112
2052
  class ProfilesCollection:
2113
2053
  """ "
prefect/states.py CHANGED
@@ -13,10 +13,6 @@ from typing_extensions import TypeGuard
13
13
 
14
14
  from prefect.client.schemas import State as State
15
15
  from prefect.client.schemas import StateDetails, StateType
16
- from prefect.deprecated.data_documents import (
17
- DataDocument,
18
- result_from_state_with_data_document,
19
- )
20
16
  from prefect.exceptions import (
21
17
  CancelledRun,
22
18
  CrashedRun,
@@ -47,7 +43,6 @@ def get_state_result(
47
43
  ):
48
44
  # Fetch defaults to `True` for sync users or async users who have opted in
49
45
  fetch = True
50
-
51
46
  if not fetch:
52
47
  if fetch is None and in_async_main_thread():
53
48
  warnings.warn(
@@ -60,13 +55,8 @@ def get_state_result(
60
55
  DeprecationWarning,
61
56
  stacklevel=2,
62
57
  )
63
- # Backwards compatibility
64
- if isinstance(state.data, DataDocument):
65
- return result_from_state_with_data_document(
66
- state, raise_on_failure=raise_on_failure
67
- )
68
- else:
69
- return state.data
58
+
59
+ return state.data
70
60
  else:
71
61
  return _get_state_result(state, raise_on_failure=raise_on_failure)
72
62
 
@@ -90,11 +80,7 @@ async def _get_state_result(state: State[R], raise_on_failure: bool) -> R:
90
80
  ):
91
81
  raise await get_state_exception(state)
92
82
 
93
- if isinstance(state.data, DataDocument):
94
- result = result_from_state_with_data_document(
95
- state, raise_on_failure=raise_on_failure
96
- )
97
- elif isinstance(state.data, BaseResult):
83
+ if isinstance(state.data, BaseResult):
98
84
  result = await state.data.get()
99
85
  elif state.data is None:
100
86
  if state.is_failed() or state.is_crashed() or state.is_cancelled():
@@ -212,10 +198,15 @@ async def exception_to_failed_state(
212
198
  # excluded from messages for now
213
199
  message = existing_message + format_exception(exc)
214
200
 
215
- return Failed(data=data, message=message, **kwargs)
201
+ state = Failed(data=data, message=message, **kwargs)
202
+ state.state_details.retriable = False
216
203
 
204
+ return state
217
205
 
218
- async def return_value_to_state(retval: R, result_factory: ResultFactory) -> State[R]:
206
+
207
+ async def return_value_to_state(
208
+ retval: R, result_factory: ResultFactory, key: str = None
209
+ ) -> State[R]:
219
210
  """
220
211
  Given a return value from a user's function, create a `State` the run should
221
212
  be placed in.
@@ -238,26 +229,21 @@ async def return_value_to_state(retval: R, result_factory: ResultFactory) -> Sta
238
229
  """
239
230
 
240
231
  if (
241
- is_state(retval)
232
+ isinstance(retval, State)
242
233
  # Check for manual creation
243
234
  and not retval.state_details.flow_run_id
244
235
  and not retval.state_details.task_run_id
245
236
  ):
246
237
  state = retval
247
-
248
- # Do not modify states with data documents attached; backwards compatibility
249
- if isinstance(state.data, DataDocument):
250
- return state
251
-
252
238
  # Unless the user has already constructed a result explicitly, use the factory
253
239
  # to update the data to the correct type
254
240
  if not isinstance(state.data, BaseResult):
255
- state.data = await result_factory.create_result(state.data)
241
+ state.data = await result_factory.create_result(state.data, key=key)
256
242
 
257
243
  return state
258
244
 
259
245
  # Determine a new state from the aggregate of contained states
260
- if is_state(retval) or is_state_iterable(retval):
246
+ if isinstance(retval, State) or is_state_iterable(retval):
261
247
  states = StateGroup(ensure_iterable(retval))
262
248
 
263
249
  # Determine the new state type
@@ -292,7 +278,7 @@ async def return_value_to_state(retval: R, result_factory: ResultFactory) -> Sta
292
278
  return State(
293
279
  type=new_state_type,
294
280
  message=message,
295
- data=await result_factory.create_result(retval),
281
+ data=await result_factory.create_result(retval, key=key),
296
282
  )
297
283
 
298
284
  # Generators aren't portable, implicitly convert them to a list.
@@ -302,7 +288,10 @@ async def return_value_to_state(retval: R, result_factory: ResultFactory) -> Sta
302
288
  data = retval
303
289
 
304
290
  # Otherwise, they just gave data and this is a completed retval
305
- return Completed(data=await result_factory.create_result(data))
291
+ if isinstance(data, BaseResult):
292
+ return Completed(data=data)
293
+ else:
294
+ return Completed(data=await result_factory.create_result(data, key=key))
306
295
 
307
296
 
308
297
  @sync_compatible
@@ -360,7 +349,7 @@ async def get_state_exception(state: State) -> BaseException:
360
349
  elif isinstance(result, str):
361
350
  return wrapper(result)
362
351
 
363
- elif is_state(result):
352
+ elif isinstance(result, State):
364
353
  # Return the exception from the inner state
365
354
  return await get_state_exception(result)
366
355
 
@@ -392,23 +381,6 @@ async def raise_state_exception(state: State) -> None:
392
381
  raise await get_state_exception(state)
393
382
 
394
383
 
395
- def is_state(obj: Any) -> TypeGuard[State]:
396
- """
397
- Check if the given object is a state instance
398
- """
399
- # We may want to narrow this to client-side state types but for now this provides
400
- # backwards compatibility
401
- try:
402
- from prefect.server.schemas.states import State as State_
403
-
404
- classes_ = (State, State_)
405
- except ImportError:
406
- classes_ = State
407
-
408
- # return isinstance(obj, (State, State_))
409
- return isinstance(obj, classes_)
410
-
411
-
412
384
  def is_state_iterable(obj: Any) -> TypeGuard[Iterable[State]]:
413
385
  """
414
386
  Check if a the given object is an iterable of states types
@@ -427,7 +399,7 @@ def is_state_iterable(obj: Any) -> TypeGuard[Iterable[State]]:
427
399
  and isinstance(obj, (list, set, tuple))
428
400
  and obj
429
401
  ):
430
- return all([is_state(o) for o in obj])
402
+ return all([isinstance(o, State) for o in obj])
431
403
  else:
432
404
  return False
433
405
 
@@ -495,7 +467,7 @@ def Scheduled(
495
467
  Returns:
496
468
  State: a Scheduled state
497
469
  """
498
- state_details = StateDetails.parse_obj(kwargs.pop("state_details", {}))
470
+ state_details = StateDetails.model_validate(kwargs.pop("state_details", {}))
499
471
  if scheduled_time is None:
500
472
  scheduled_time = pendulum.now("UTC")
501
473
  elif state_details.scheduled_time:
@@ -581,7 +553,7 @@ def Paused(
581
553
  Returns:
582
554
  State: a Paused state
583
555
  """
584
- state_details = StateDetails.parse_obj(kwargs.pop("state_details", {}))
556
+ state_details = StateDetails.model_validate(kwargs.pop("state_details", {}))
585
557
 
586
558
  if state_details.pause_timeout:
587
559
  raise ValueError("An extra pause timeout was provided in state_details")