prefect-client 2.19.3__py3-none-any.whl → 3.0.0rc1__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 (239) 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/system.py +22 -11
  26. prefect/blocks/webhook.py +2 -9
  27. prefect/client/base.py +4 -4
  28. prefect/client/cloud.py +8 -13
  29. prefect/client/orchestration.py +347 -341
  30. prefect/client/schemas/actions.py +92 -86
  31. prefect/client/schemas/filters.py +20 -40
  32. prefect/client/schemas/objects.py +147 -145
  33. prefect/client/schemas/responses.py +16 -24
  34. prefect/client/schemas/schedules.py +47 -35
  35. prefect/client/subscriptions.py +2 -2
  36. prefect/client/utilities.py +5 -2
  37. prefect/concurrency/asyncio.py +3 -1
  38. prefect/concurrency/events.py +1 -1
  39. prefect/concurrency/services.py +6 -3
  40. prefect/context.py +195 -27
  41. prefect/deployments/__init__.py +5 -6
  42. prefect/deployments/base.py +7 -5
  43. prefect/deployments/flow_runs.py +185 -0
  44. prefect/deployments/runner.py +50 -45
  45. prefect/deployments/schedules.py +28 -23
  46. prefect/deployments/steps/__init__.py +0 -1
  47. prefect/deployments/steps/core.py +1 -0
  48. prefect/deployments/steps/pull.py +7 -21
  49. prefect/engine.py +12 -2422
  50. prefect/events/actions.py +17 -23
  51. prefect/events/cli/automations.py +19 -6
  52. prefect/events/clients.py +14 -37
  53. prefect/events/filters.py +14 -18
  54. prefect/events/related.py +2 -2
  55. prefect/events/schemas/__init__.py +0 -5
  56. prefect/events/schemas/automations.py +55 -46
  57. prefect/events/schemas/deployment_triggers.py +7 -197
  58. prefect/events/schemas/events.py +34 -65
  59. prefect/events/schemas/labelling.py +10 -14
  60. prefect/events/utilities.py +2 -3
  61. prefect/events/worker.py +2 -3
  62. prefect/filesystems.py +6 -517
  63. prefect/{new_flow_engine.py → flow_engine.py} +313 -72
  64. prefect/flow_runs.py +377 -5
  65. prefect/flows.py +248 -165
  66. prefect/futures.py +186 -345
  67. prefect/infrastructure/__init__.py +0 -27
  68. prefect/infrastructure/provisioners/__init__.py +5 -3
  69. prefect/infrastructure/provisioners/cloud_run.py +11 -6
  70. prefect/infrastructure/provisioners/container_instance.py +11 -7
  71. prefect/infrastructure/provisioners/ecs.py +6 -4
  72. prefect/infrastructure/provisioners/modal.py +8 -5
  73. prefect/input/actions.py +2 -4
  74. prefect/input/run_input.py +5 -7
  75. prefect/logging/formatters.py +0 -2
  76. prefect/logging/handlers.py +3 -11
  77. prefect/logging/loggers.py +2 -2
  78. prefect/manifests.py +2 -1
  79. prefect/records/__init__.py +1 -0
  80. prefect/records/result_store.py +42 -0
  81. prefect/records/store.py +9 -0
  82. prefect/results.py +43 -39
  83. prefect/runner/runner.py +9 -9
  84. prefect/runner/server.py +6 -10
  85. prefect/runner/storage.py +3 -8
  86. prefect/runner/submit.py +2 -2
  87. prefect/runner/utils.py +2 -2
  88. prefect/serializers.py +24 -35
  89. prefect/server/api/collections_data/views/aggregate-worker-metadata.json +5 -14
  90. prefect/settings.py +70 -133
  91. prefect/states.py +17 -47
  92. prefect/task_engine.py +697 -58
  93. prefect/task_runners.py +269 -301
  94. prefect/task_server.py +53 -34
  95. prefect/tasks.py +327 -337
  96. prefect/transactions.py +220 -0
  97. prefect/types/__init__.py +61 -82
  98. prefect/utilities/asyncutils.py +195 -136
  99. prefect/utilities/callables.py +121 -41
  100. prefect/utilities/collections.py +23 -38
  101. prefect/utilities/dispatch.py +11 -3
  102. prefect/utilities/dockerutils.py +4 -0
  103. prefect/utilities/engine.py +140 -20
  104. prefect/utilities/importtools.py +26 -27
  105. prefect/utilities/pydantic.py +128 -38
  106. prefect/utilities/schema_tools/hydration.py +5 -1
  107. prefect/utilities/templating.py +12 -2
  108. prefect/variables.py +78 -61
  109. prefect/workers/__init__.py +0 -1
  110. prefect/workers/base.py +15 -17
  111. prefect/workers/process.py +3 -8
  112. prefect/workers/server.py +2 -2
  113. {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/METADATA +22 -21
  114. prefect_client-3.0.0rc1.dist-info/RECORD +176 -0
  115. prefect/_internal/pydantic/_base_model.py +0 -51
  116. prefect/_internal/pydantic/_compat.py +0 -82
  117. prefect/_internal/pydantic/_flags.py +0 -20
  118. prefect/_internal/pydantic/_types.py +0 -8
  119. prefect/_internal/pydantic/utilities/__init__.py +0 -0
  120. prefect/_internal/pydantic/utilities/config_dict.py +0 -72
  121. prefect/_internal/pydantic/utilities/field_validator.py +0 -150
  122. prefect/_internal/pydantic/utilities/model_construct.py +0 -56
  123. prefect/_internal/pydantic/utilities/model_copy.py +0 -55
  124. prefect/_internal/pydantic/utilities/model_dump.py +0 -136
  125. prefect/_internal/pydantic/utilities/model_dump_json.py +0 -112
  126. prefect/_internal/pydantic/utilities/model_fields.py +0 -50
  127. prefect/_internal/pydantic/utilities/model_fields_set.py +0 -29
  128. prefect/_internal/pydantic/utilities/model_json_schema.py +0 -82
  129. prefect/_internal/pydantic/utilities/model_rebuild.py +0 -80
  130. prefect/_internal/pydantic/utilities/model_validate.py +0 -75
  131. prefect/_internal/pydantic/utilities/model_validate_json.py +0 -68
  132. prefect/_internal/pydantic/utilities/model_validator.py +0 -87
  133. prefect/_internal/pydantic/utilities/type_adapter.py +0 -71
  134. prefect/_vendor/__init__.py +0 -0
  135. prefect/_vendor/fastapi/__init__.py +0 -25
  136. prefect/_vendor/fastapi/applications.py +0 -946
  137. prefect/_vendor/fastapi/background.py +0 -3
  138. prefect/_vendor/fastapi/concurrency.py +0 -44
  139. prefect/_vendor/fastapi/datastructures.py +0 -58
  140. prefect/_vendor/fastapi/dependencies/__init__.py +0 -0
  141. prefect/_vendor/fastapi/dependencies/models.py +0 -64
  142. prefect/_vendor/fastapi/dependencies/utils.py +0 -877
  143. prefect/_vendor/fastapi/encoders.py +0 -177
  144. prefect/_vendor/fastapi/exception_handlers.py +0 -40
  145. prefect/_vendor/fastapi/exceptions.py +0 -46
  146. prefect/_vendor/fastapi/logger.py +0 -3
  147. prefect/_vendor/fastapi/middleware/__init__.py +0 -1
  148. prefect/_vendor/fastapi/middleware/asyncexitstack.py +0 -25
  149. prefect/_vendor/fastapi/middleware/cors.py +0 -3
  150. prefect/_vendor/fastapi/middleware/gzip.py +0 -3
  151. prefect/_vendor/fastapi/middleware/httpsredirect.py +0 -3
  152. prefect/_vendor/fastapi/middleware/trustedhost.py +0 -3
  153. prefect/_vendor/fastapi/middleware/wsgi.py +0 -3
  154. prefect/_vendor/fastapi/openapi/__init__.py +0 -0
  155. prefect/_vendor/fastapi/openapi/constants.py +0 -2
  156. prefect/_vendor/fastapi/openapi/docs.py +0 -203
  157. prefect/_vendor/fastapi/openapi/models.py +0 -480
  158. prefect/_vendor/fastapi/openapi/utils.py +0 -485
  159. prefect/_vendor/fastapi/param_functions.py +0 -340
  160. prefect/_vendor/fastapi/params.py +0 -453
  161. prefect/_vendor/fastapi/requests.py +0 -4
  162. prefect/_vendor/fastapi/responses.py +0 -40
  163. prefect/_vendor/fastapi/routing.py +0 -1331
  164. prefect/_vendor/fastapi/security/__init__.py +0 -15
  165. prefect/_vendor/fastapi/security/api_key.py +0 -98
  166. prefect/_vendor/fastapi/security/base.py +0 -6
  167. prefect/_vendor/fastapi/security/http.py +0 -172
  168. prefect/_vendor/fastapi/security/oauth2.py +0 -227
  169. prefect/_vendor/fastapi/security/open_id_connect_url.py +0 -34
  170. prefect/_vendor/fastapi/security/utils.py +0 -10
  171. prefect/_vendor/fastapi/staticfiles.py +0 -1
  172. prefect/_vendor/fastapi/templating.py +0 -3
  173. prefect/_vendor/fastapi/testclient.py +0 -1
  174. prefect/_vendor/fastapi/types.py +0 -3
  175. prefect/_vendor/fastapi/utils.py +0 -235
  176. prefect/_vendor/fastapi/websockets.py +0 -7
  177. prefect/_vendor/starlette/__init__.py +0 -1
  178. prefect/_vendor/starlette/_compat.py +0 -28
  179. prefect/_vendor/starlette/_exception_handler.py +0 -80
  180. prefect/_vendor/starlette/_utils.py +0 -88
  181. prefect/_vendor/starlette/applications.py +0 -261
  182. prefect/_vendor/starlette/authentication.py +0 -159
  183. prefect/_vendor/starlette/background.py +0 -43
  184. prefect/_vendor/starlette/concurrency.py +0 -59
  185. prefect/_vendor/starlette/config.py +0 -151
  186. prefect/_vendor/starlette/convertors.py +0 -87
  187. prefect/_vendor/starlette/datastructures.py +0 -707
  188. prefect/_vendor/starlette/endpoints.py +0 -130
  189. prefect/_vendor/starlette/exceptions.py +0 -60
  190. prefect/_vendor/starlette/formparsers.py +0 -276
  191. prefect/_vendor/starlette/middleware/__init__.py +0 -17
  192. prefect/_vendor/starlette/middleware/authentication.py +0 -52
  193. prefect/_vendor/starlette/middleware/base.py +0 -220
  194. prefect/_vendor/starlette/middleware/cors.py +0 -176
  195. prefect/_vendor/starlette/middleware/errors.py +0 -265
  196. prefect/_vendor/starlette/middleware/exceptions.py +0 -74
  197. prefect/_vendor/starlette/middleware/gzip.py +0 -113
  198. prefect/_vendor/starlette/middleware/httpsredirect.py +0 -19
  199. prefect/_vendor/starlette/middleware/sessions.py +0 -82
  200. prefect/_vendor/starlette/middleware/trustedhost.py +0 -64
  201. prefect/_vendor/starlette/middleware/wsgi.py +0 -147
  202. prefect/_vendor/starlette/requests.py +0 -328
  203. prefect/_vendor/starlette/responses.py +0 -347
  204. prefect/_vendor/starlette/routing.py +0 -933
  205. prefect/_vendor/starlette/schemas.py +0 -154
  206. prefect/_vendor/starlette/staticfiles.py +0 -248
  207. prefect/_vendor/starlette/status.py +0 -199
  208. prefect/_vendor/starlette/templating.py +0 -231
  209. prefect/_vendor/starlette/testclient.py +0 -804
  210. prefect/_vendor/starlette/types.py +0 -30
  211. prefect/_vendor/starlette/websockets.py +0 -193
  212. prefect/agent.py +0 -698
  213. prefect/deployments/deployments.py +0 -1042
  214. prefect/deprecated/__init__.py +0 -0
  215. prefect/deprecated/data_documents.py +0 -350
  216. prefect/deprecated/packaging/__init__.py +0 -12
  217. prefect/deprecated/packaging/base.py +0 -96
  218. prefect/deprecated/packaging/docker.py +0 -146
  219. prefect/deprecated/packaging/file.py +0 -92
  220. prefect/deprecated/packaging/orion.py +0 -80
  221. prefect/deprecated/packaging/serializers.py +0 -171
  222. prefect/events/instrument.py +0 -135
  223. prefect/infrastructure/base.py +0 -323
  224. prefect/infrastructure/container.py +0 -818
  225. prefect/infrastructure/kubernetes.py +0 -920
  226. prefect/infrastructure/process.py +0 -289
  227. prefect/new_task_engine.py +0 -423
  228. prefect/pydantic/__init__.py +0 -76
  229. prefect/pydantic/main.py +0 -39
  230. prefect/software/__init__.py +0 -2
  231. prefect/software/base.py +0 -50
  232. prefect/software/conda.py +0 -199
  233. prefect/software/pip.py +0 -122
  234. prefect/software/python.py +0 -52
  235. prefect/workers/block.py +0 -218
  236. prefect_client-2.19.3.dist-info/RECORD +0 -292
  237. {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/LICENSE +0 -0
  238. {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.dist-info}/WHEEL +0 -0
  239. {prefect_client-2.19.3.dist-info → prefect_client-3.0.0rc1.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,
@@ -1313,7 +1278,7 @@ PREFECT_UI_ENABLED = Setting(
1313
1278
  """Whether or not to serve the Prefect UI."""
1314
1279
 
1315
1280
  PREFECT_UI_API_URL = Setting(
1316
- str,
1281
+ Optional[str],
1317
1282
  default=None,
1318
1283
  value_callback=default_ui_api_url,
1319
1284
  )
@@ -1401,16 +1366,6 @@ PREFECT_EXPERIMENTAL_ENABLE_STATES_ON_FLOW_RUN_GRAPH = Setting(bool, default=Tru
1401
1366
  Whether or not to enable flow run states on the flow run graph.
1402
1367
  """
1403
1368
 
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
1369
  PREFECT_EXPERIMENTAL_ENABLE_WORKERS = Setting(bool, default=True)
1415
1370
  """
1416
1371
  Whether or not to enable experimental Prefect workers.
@@ -1459,13 +1414,6 @@ Whether or not to enable flow run input.
1459
1414
 
1460
1415
  # Prefect Events feature flags
1461
1416
 
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
1417
  PREFECT_RUNNER_PROCESS_LIMIT = Setting(int, default=5)
1470
1418
  """
1471
1419
  Maximum number of processes a runner will execute in parallel.
@@ -1538,6 +1486,11 @@ PREFECT_WORKER_WEBSERVER_PORT = Setting(
1538
1486
  The port the worker's webserver should bind to.
1539
1487
  """
1540
1488
 
1489
+ PREFECT_API_SERVICES_TASK_SCHEDULING_ENABLED = Setting(bool, default=True)
1490
+ """
1491
+ Whether or not to start the task scheduling service in the server application.
1492
+ """
1493
+
1541
1494
  PREFECT_TASK_SCHEDULING_DEFAULT_STORAGE_BLOCK = Setting(
1542
1495
  str,
1543
1496
  default="local-file-system/prefect-task-scheduling",
@@ -1604,42 +1557,33 @@ PREFECT_EXPERIMENTAL_WARN_WORKSPACE_DASHBOARD = Setting(bool, default=False)
1604
1557
  Whether or not to warn when the experimental workspace dashboard is enabled.
1605
1558
  """
1606
1559
 
1607
- PREFECT_EXPERIMENTAL_ENABLE_TASK_SCHEDULING = Setting(bool, default=False)
1608
- """
1609
- Whether or not to enable experimental task scheduling.
1610
- """
1611
-
1612
1560
  PREFECT_EXPERIMENTAL_ENABLE_WORK_QUEUE_STATUS = Setting(bool, default=True)
1613
1561
  """
1614
1562
  Whether or not to enable experimental work queue status in-place of work queue health.
1615
1563
  """
1616
1564
 
1617
- PREFECT_EXPERIMENTAL_ENABLE_NEW_ENGINE = Setting(bool, default=False)
1618
- """
1619
- Whether or not to enable experimental new engine.
1620
- """
1621
-
1622
1565
  PREFECT_EXPERIMENTAL_DISABLE_SYNC_COMPAT = Setting(bool, default=False)
1623
1566
  """
1624
1567
  Whether or not to disable the sync_compatible decorator utility.
1625
1568
  """
1626
1569
 
1570
+ PREFECT_EXPERIMENTAL_ENABLE_SCHEDULE_CONCURRENCY = Setting(bool, default=False)
1627
1571
 
1628
1572
  # Defaults -----------------------------------------------------------------------------
1629
1573
 
1630
1574
  PREFECT_DEFAULT_RESULT_STORAGE_BLOCK = Setting(
1631
- str,
1575
+ Optional[str],
1632
1576
  default=None,
1633
1577
  )
1634
1578
  """The `block-type/block-document` slug of a block to use as the default result storage."""
1635
1579
 
1636
- PREFECT_DEFAULT_WORK_POOL_NAME = Setting(str, default=None)
1580
+ PREFECT_DEFAULT_WORK_POOL_NAME = Setting(Optional[str], default=None)
1637
1581
  """
1638
1582
  The default work pool to deploy to.
1639
1583
  """
1640
1584
 
1641
1585
  PREFECT_DEFAULT_DOCKER_BUILD_NAMESPACE = Setting(
1642
- str,
1586
+ Optional[str],
1643
1587
  default=None,
1644
1588
  )
1645
1589
  """
@@ -1659,7 +1603,7 @@ Defaults to the root path.
1659
1603
  """
1660
1604
 
1661
1605
  PREFECT_UI_STATIC_DIRECTORY = Setting(
1662
- str,
1606
+ Optional[str],
1663
1607
  default=None,
1664
1608
  )
1665
1609
  """
@@ -1756,16 +1700,6 @@ How long to cache related resource data for emitting server-side vents
1756
1700
  """
1757
1701
 
1758
1702
 
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
1703
  # Deprecated settings ------------------------------------------------------------------
1770
1704
 
1771
1705
 
@@ -1783,10 +1717,14 @@ for __name, __setting in SETTING_VARIABLES.items():
1783
1717
 
1784
1718
  # Dynamically create a pydantic model that includes all of our settings
1785
1719
 
1786
- SettingsFieldsMixin = create_model(
1720
+
1721
+ class PrefectBaseSettings(BaseSettings):
1722
+ model_config = SettingsConfigDict(extra="ignore")
1723
+
1724
+
1725
+ SettingsFieldsMixin: Type[BaseSettings] = create_model(
1787
1726
  "SettingsFieldsMixin",
1788
- # Inheriting from `BaseSettings` provides environment variable loading
1789
- __base__=BaseSettings,
1727
+ __base__=PrefectBaseSettings, # Inheriting from `BaseSettings` provides environment variable loading
1790
1728
  **{
1791
1729
  setting.name: (setting.type, setting.field)
1792
1730
  for setting in SETTING_VARIABLES.values()
@@ -1828,32 +1766,33 @@ class Settings(SettingsFieldsMixin):
1828
1766
  value = setting.value_callback(self, value)
1829
1767
  return value
1830
1768
 
1831
- @validator(PREFECT_LOGGING_LEVEL.name, PREFECT_LOGGING_SERVER_LEVEL.name)
1769
+ @field_validator(PREFECT_LOGGING_LEVEL.name, PREFECT_LOGGING_SERVER_LEVEL.name)
1832
1770
  def check_valid_log_level(cls, value):
1833
1771
  if isinstance(value, str):
1834
1772
  value = value.upper()
1835
1773
  logging._checkLevel(value)
1836
1774
  return value
1837
1775
 
1838
- @root_validator
1839
- def post_root_validators(cls, values):
1776
+ @model_validator(mode="after")
1777
+ def emit_warnings(self):
1840
1778
  """
1841
1779
  Add root validation functions for settings here.
1842
1780
  """
1843
1781
  # TODO: We could probably register these dynamically but this is the simpler
1844
1782
  # approach for now. We can explore more interesting validation features
1845
1783
  # in the future.
1784
+ values = self.model_dump()
1846
1785
  values = max_log_size_smaller_than_batch_size(values)
1847
1786
  values = warn_on_database_password_value_without_usage(values)
1848
1787
  if not values["PREFECT_SILENCE_API_URL_MISCONFIGURATION"]:
1849
1788
  values = warn_on_misconfigured_api_url(values)
1850
- return values
1789
+ return self
1851
1790
 
1852
1791
  def copy_with_update(
1853
1792
  self,
1854
- updates: Mapping[Setting, Any] = None,
1855
- set_defaults: Mapping[Setting, Any] = None,
1856
- restore_defaults: Iterable[Setting] = None,
1793
+ updates: Optional[Mapping[Setting, Any]] = None,
1794
+ set_defaults: Optional[Mapping[Setting, Any]] = None,
1795
+ restore_defaults: Optional[Iterable[Setting]] = None,
1857
1796
  ) -> "Settings":
1858
1797
  """
1859
1798
  Create a new `Settings` object with validation.
@@ -1876,7 +1815,7 @@ class Settings(SettingsFieldsMixin):
1876
1815
  return self.__class__(
1877
1816
  **{
1878
1817
  **{setting.name: value for setting, value in set_defaults.items()},
1879
- **self.dict(exclude_unset=True, exclude=restore_defaults_names),
1818
+ **self.model_dump(exclude_unset=True, exclude=restore_defaults_names),
1880
1819
  **{setting.name: value for setting, value in updates.items()},
1881
1820
  }
1882
1821
  )
@@ -1885,7 +1824,7 @@ class Settings(SettingsFieldsMixin):
1885
1824
  """
1886
1825
  Returns a copy of this settings object with secret setting values obfuscated.
1887
1826
  """
1888
- settings = self.copy(
1827
+ settings = self.model_copy(
1889
1828
  update={
1890
1829
  setting.name: obfuscate(self.value_of(setting))
1891
1830
  for setting in SETTING_VARIABLES.values()
@@ -1896,7 +1835,11 @@ class Settings(SettingsFieldsMixin):
1896
1835
  )
1897
1836
  # Ensure that settings that have not been marked as "set" before are still so
1898
1837
  # after we have updated their value above
1899
- settings.__fields_set__.intersection_update(self.__fields_set__)
1838
+ with warnings.catch_warnings():
1839
+ warnings.simplefilter(
1840
+ "ignore", category=pydantic.warnings.PydanticDeprecatedSince20
1841
+ )
1842
+ settings.__fields_set__.intersection_update(self.__fields_set__)
1900
1843
  return settings
1901
1844
 
1902
1845
  def hash_key(self) -> str:
@@ -1908,7 +1851,7 @@ class Settings(SettingsFieldsMixin):
1908
1851
  return str(hash(tuple((key, value) for key, value in env_variables.items())))
1909
1852
 
1910
1853
  def to_environment_variables(
1911
- self, include: Iterable[Setting] = None, exclude_unset: bool = False
1854
+ self, include: Optional[Iterable[Setting]] = None, exclude_unset: bool = False
1912
1855
  ) -> Dict[str, str]:
1913
1856
  """
1914
1857
  Convert the settings object to environment variables.
@@ -1932,7 +1875,7 @@ class Settings(SettingsFieldsMixin):
1932
1875
  set_keys = {
1933
1876
  # Collect all of the "set" keys and cast to `Setting` objects
1934
1877
  SETTING_VARIABLES[key]
1935
- for key in self.dict(exclude_unset=True)
1878
+ for key in self.model_dump(exclude_unset=True)
1936
1879
  }
1937
1880
  include.intersection_update(set_keys)
1938
1881
 
@@ -1943,23 +1886,19 @@ class Settings(SettingsFieldsMixin):
1943
1886
  "Invalid type {type(key).__name__!r} for key in `include`."
1944
1887
  )
1945
1888
 
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
- }
1889
+ env: dict[str, Any] = self.model_dump(
1890
+ mode="json", include={s.name for s in include}
1891
+ )
1952
1892
 
1953
1893
  # Cast to strings and drop null values
1954
1894
  return {key: str(value) for key, value in env.items() if value is not None}
1955
1895
 
1956
- class Config:
1957
- frozen = True
1896
+ model_config = ConfigDict(frozen=True)
1958
1897
 
1959
1898
 
1960
1899
  # Functions to instantiate `Settings` instances
1961
1900
 
1962
- _DEFAULTS_CACHE: Settings = None
1901
+ _DEFAULTS_CACHE: Optional[Settings] = None
1963
1902
  _FROM_ENV_CACHE: Dict[int, Settings] = {}
1964
1903
 
1965
1904
 
@@ -2066,9 +2005,10 @@ class Profile(BaseModel):
2066
2005
 
2067
2006
  name: str
2068
2007
  settings: Dict[Setting, Any] = Field(default_factory=dict)
2069
- source: Optional[Path]
2008
+ source: Optional[Path] = None
2009
+ model_config = ConfigDict(extra="ignore", arbitrary_types_allowed=True)
2070
2010
 
2071
- @validator("settings", pre=True)
2011
+ @field_validator("settings", mode="before")
2072
2012
  def map_names_to_settings(cls, value):
2073
2013
  return validate_settings(value)
2074
2014
 
@@ -2105,9 +2045,6 @@ class Profile(BaseModel):
2105
2045
  changed.append((setting, setting.deprecated_renamed_to))
2106
2046
  return changed
2107
2047
 
2108
- class Config:
2109
- arbitrary_types_allowed = True
2110
-
2111
2048
 
2112
2049
  class ProfilesCollection:
2113
2050
  """ "
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,7 +198,10 @@ 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
203
+
204
+ return state
216
205
 
217
206
 
218
207
  async def return_value_to_state(retval: R, result_factory: ResultFactory) -> State[R]:
@@ -238,17 +227,12 @@ async def return_value_to_state(retval: R, result_factory: ResultFactory) -> Sta
238
227
  """
239
228
 
240
229
  if (
241
- is_state(retval)
230
+ isinstance(retval, State)
242
231
  # Check for manual creation
243
232
  and not retval.state_details.flow_run_id
244
233
  and not retval.state_details.task_run_id
245
234
  ):
246
235
  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
236
  # Unless the user has already constructed a result explicitly, use the factory
253
237
  # to update the data to the correct type
254
238
  if not isinstance(state.data, BaseResult):
@@ -257,7 +241,7 @@ async def return_value_to_state(retval: R, result_factory: ResultFactory) -> Sta
257
241
  return state
258
242
 
259
243
  # Determine a new state from the aggregate of contained states
260
- if is_state(retval) or is_state_iterable(retval):
244
+ if isinstance(retval, State) or is_state_iterable(retval):
261
245
  states = StateGroup(ensure_iterable(retval))
262
246
 
263
247
  # Determine the new state type
@@ -302,7 +286,10 @@ async def return_value_to_state(retval: R, result_factory: ResultFactory) -> Sta
302
286
  data = retval
303
287
 
304
288
  # Otherwise, they just gave data and this is a completed retval
305
- return Completed(data=await result_factory.create_result(data))
289
+ if isinstance(data, BaseResult):
290
+ return Completed(data=data)
291
+ else:
292
+ return Completed(data=await result_factory.create_result(data))
306
293
 
307
294
 
308
295
  @sync_compatible
@@ -360,7 +347,7 @@ async def get_state_exception(state: State) -> BaseException:
360
347
  elif isinstance(result, str):
361
348
  return wrapper(result)
362
349
 
363
- elif is_state(result):
350
+ elif isinstance(result, State):
364
351
  # Return the exception from the inner state
365
352
  return await get_state_exception(result)
366
353
 
@@ -392,23 +379,6 @@ async def raise_state_exception(state: State) -> None:
392
379
  raise await get_state_exception(state)
393
380
 
394
381
 
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
382
  def is_state_iterable(obj: Any) -> TypeGuard[Iterable[State]]:
413
383
  """
414
384
  Check if a the given object is an iterable of states types
@@ -427,7 +397,7 @@ def is_state_iterable(obj: Any) -> TypeGuard[Iterable[State]]:
427
397
  and isinstance(obj, (list, set, tuple))
428
398
  and obj
429
399
  ):
430
- return all([is_state(o) for o in obj])
400
+ return all([isinstance(o, State) for o in obj])
431
401
  else:
432
402
  return False
433
403
 
@@ -495,7 +465,7 @@ def Scheduled(
495
465
  Returns:
496
466
  State: a Scheduled state
497
467
  """
498
- state_details = StateDetails.parse_obj(kwargs.pop("state_details", {}))
468
+ state_details = StateDetails.model_validate(kwargs.pop("state_details", {}))
499
469
  if scheduled_time is None:
500
470
  scheduled_time = pendulum.now("UTC")
501
471
  elif state_details.scheduled_time:
@@ -581,7 +551,7 @@ def Paused(
581
551
  Returns:
582
552
  State: a Paused state
583
553
  """
584
- state_details = StateDetails.parse_obj(kwargs.pop("state_details", {}))
554
+ state_details = StateDetails.model_validate(kwargs.pop("state_details", {}))
585
555
 
586
556
  if state_details.pause_timeout:
587
557
  raise ValueError("An extra pause timeout was provided in state_details")