prefect-client 2.16.5__py3-none-any.whl → 2.16.6__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.
@@ -10,4 +10,4 @@ from pydantic.version import VERSION as PYDANTIC_VERSION
10
10
 
11
11
  HAS_PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
12
12
 
13
- from ._compat import model_dump, IncEx, model_json_schema
13
+ from ._compat import model_dump, model_json_schema, model_validate, IncEx
@@ -178,3 +178,36 @@ def model_json_schema(
178
178
  by_alias=by_alias,
179
179
  ref_template=ref_template,
180
180
  )
181
+
182
+
183
+ def model_validate(
184
+ model: Type[BaseModel],
185
+ obj: Any,
186
+ *,
187
+ strict: bool = False,
188
+ from_attributes: bool = False,
189
+ context: Optional[Dict[str, Any]] = None,
190
+ ) -> Union[BaseModel, Dict[str, Any]]:
191
+ """Validate a pydantic model instance.
192
+
193
+ Args:
194
+ obj: The object to validate.
195
+ strict: Whether to enforce types strictly.
196
+ from_attributes: Whether to extract data from object attributes.
197
+ context: Additional context to pass to the validator.
198
+
199
+ Raises:
200
+ ValidationError: If the object could not be validated.
201
+
202
+ Returns:
203
+ The validated model instance.
204
+ """
205
+ if is_pydantic_v2_compatible(fn_name="model_validate"):
206
+ return model.model_validate(
207
+ obj=obj,
208
+ strict=strict,
209
+ from_attributes=from_attributes,
210
+ context=context,
211
+ )
212
+
213
+ return model.parse_obj(obj)
@@ -0,0 +1,48 @@
1
+ import inspect
2
+ import typing
3
+
4
+ from prefect._internal.pydantic import HAS_PYDANTIC_V2
5
+
6
+ if HAS_PYDANTIC_V2:
7
+ from pydantic.v1 import BaseModel as V1BaseModel
8
+ else:
9
+ from pydantic import BaseModel as V1BaseModel
10
+
11
+
12
+ def is_v1_model(v) -> bool:
13
+ if isinstance(v, V1BaseModel):
14
+ return True
15
+ try:
16
+ if inspect.isclass(v) and issubclass(v, V1BaseModel):
17
+ return True
18
+ except TypeError:
19
+ pass
20
+
21
+ return False
22
+
23
+
24
+ def is_v1_type(v) -> bool:
25
+ if HAS_PYDANTIC_V2:
26
+ if is_v1_model(v):
27
+ return True
28
+
29
+ try:
30
+ return v.__module__.startswith("pydantic.v1.types")
31
+ except AttributeError:
32
+ return False
33
+
34
+ return True
35
+
36
+
37
+ def has_v1_type_as_param(signature: inspect.Signature) -> bool:
38
+ parameters = signature.parameters.values()
39
+ for p in parameters:
40
+ # check if this parameter is a v1 model
41
+ if is_v1_type(p.annotation):
42
+ return True
43
+
44
+ # check if this parameter is a collection of types
45
+ for v in typing.get_args(p.annotation):
46
+ if is_v1_type(v):
47
+ return True
48
+ return False
@@ -7,7 +7,7 @@ import typing as t
7
7
  import pendulum
8
8
  import pydantic
9
9
  from pydantic import BaseModel as V2BaseModel
10
- from pydantic import ConfigDict, create_model
10
+ from pydantic import ConfigDict, PydanticUndefinedAnnotation, create_model
11
11
  from pydantic.type_adapter import TypeAdapter
12
12
 
13
13
  from prefect._internal.pydantic.annotations.pendulum import (
@@ -106,7 +106,11 @@ def create_v2_schema(
106
106
  model = create_model(
107
107
  name_, __config__=model_cfg, __base__=model_base, **model_fields
108
108
  )
109
- adapter = TypeAdapter(model)
109
+ try:
110
+ adapter = TypeAdapter(model)
111
+ except PydanticUndefinedAnnotation as exc:
112
+ # in v1 this raises a TypeError, which is handled by parameter_schema
113
+ raise TypeError(exc.message)
110
114
 
111
115
  # root model references under #definitions
112
116
  schema = adapter.json_schema(
prefect/client/cloud.py CHANGED
@@ -85,7 +85,10 @@ class CloudClient:
85
85
  await self.read_workspaces()
86
86
 
87
87
  async def read_workspaces(self) -> List[Workspace]:
88
- return pydantic.parse_obj_as(List[Workspace], await self.get("/me/workspaces"))
88
+ workspaces = pydantic.parse_obj_as(
89
+ List[Workspace], await self.get("/me/workspaces")
90
+ )
91
+ return workspaces
89
92
 
90
93
  async def read_worker_metadata(self) -> Dict[str, Any]:
91
94
  configured_url = prefect.settings.PREFECT_API_URL.value()
prefect/settings.py CHANGED
@@ -1235,7 +1235,7 @@ Note this setting only applies when calling `prefect server start`; if hosting t
1235
1235
  API with another tool you will need to configure this there instead.
1236
1236
  """
1237
1237
 
1238
- PREFECT_SERVER_CSRF_PROTECTION_ENABLED = Setting(bool, default=False)
1238
+ PREFECT_SERVER_CSRF_PROTECTION_ENABLED = Setting(bool, default=True)
1239
1239
  """
1240
1240
  Controls the activation of CSRF protection for the Prefect server API.
1241
1241
 
@@ -9,13 +9,13 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
9
9
  import cloudpickle
10
10
 
11
11
  from prefect._internal.pydantic import HAS_PYDANTIC_V2
12
+ from prefect._internal.pydantic.v1_schema import has_v1_type_as_param
12
13
 
13
14
  if HAS_PYDANTIC_V2:
14
15
  import pydantic.v1 as pydantic
15
16
 
16
17
  from prefect._internal.pydantic.v2_schema import (
17
18
  create_v2_schema,
18
- has_v2_type_as_param,
19
19
  process_v2_params,
20
20
  )
21
21
  else:
@@ -325,7 +325,7 @@ def parameter_schema(fn: Callable) -> ParameterSchema:
325
325
  class ModelConfig:
326
326
  arbitrary_types_allowed = True
327
327
 
328
- if HAS_PYDANTIC_V2 and has_v2_type_as_param(signature):
328
+ if HAS_PYDANTIC_V2 and not has_v1_type_as_param(signature):
329
329
  create_schema = create_v2_schema
330
330
  process_params = process_v2_params
331
331
  else:
@@ -149,9 +149,13 @@ def null_handler(obj: Dict, ctx: HydrationContext):
149
149
  @handler("json")
150
150
  def json_handler(obj: Dict, ctx: HydrationContext):
151
151
  if "value" in obj:
152
+ if isinstance(obj["value"], dict):
153
+ dehydrated_json = _hydrate(obj["value"], ctx)
154
+ else:
155
+ dehydrated_json = obj["value"]
152
156
  try:
153
- return json.loads(obj["value"])
154
- except json.decoder.JSONDecodeError as e:
157
+ return json.loads(dehydrated_json)
158
+ except (json.decoder.JSONDecodeError, TypeError) as e:
155
159
  return InvalidJSON(detail=str(e))
156
160
  else:
157
161
  # If `value` is not in the object, we need special handling to help
@@ -166,11 +170,15 @@ def json_handler(obj: Dict, ctx: HydrationContext):
166
170
  @handler("workspace_variable")
167
171
  def workspace_variable_handler(obj: Dict, ctx: HydrationContext):
168
172
  if "variable_name" in obj:
169
- variable = obj["variable_name"]
170
- if variable in ctx.workspace_variables:
171
- return ctx.workspace_variables[variable]
173
+ if isinstance(obj["variable_name"], dict):
174
+ dehydrated_variable = _hydrate(obj["variable_name"], ctx)
175
+ else:
176
+ dehydrated_variable = obj["variable_name"]
177
+
178
+ if dehydrated_variable in ctx.workspace_variables:
179
+ return ctx.workspace_variables[dehydrated_variable]
172
180
  else:
173
- return WorkspaceVariableNotFound(detail=variable)
181
+ return WorkspaceVariableNotFound(detail=dehydrated_variable)
174
182
  else:
175
183
  # Special handling if `variable_name` is not in the object.
176
184
  # If an object looks like {"__prefect_kind": "workspace_variable"}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prefect-client
3
- Version: 2.16.5
3
+ Version: 2.16.6
4
4
  Summary: Workflow orchestration and management.
5
5
  Home-page: https://www.prefect.io
6
6
  Author: Prefect Technologies, Inc.
@@ -16,7 +16,7 @@ prefect/profiles.toml,sha256=1Tz7nKBDTDXL_6KPJSeB7ok0Vx_aQJ_p0AUmbnzDLzw,39
16
16
  prefect/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  prefect/results.py,sha256=FgudRagwoNKVKR5590I4AN0mxgYoyXG_7Q1HVoMXdaU,24731
18
18
  prefect/serializers.py,sha256=sSbe40Ipj-d6VuzBae5k2ao9lkMUZpIXcLtD7f2a7cE,10852
19
- prefect/settings.py,sha256=3xU5DQQglwa7MFnYQ6GqhWHbdIis81Ehnj1fMa7d30M,71067
19
+ prefect/settings.py,sha256=XYVYB-SsFIwCel_WZBaauBTg63nueTp6djf0F1bp7OE,71066
20
20
  prefect/states.py,sha256=-Ud4AUom3Qu-HQ4hOLvfVZuuF-b_ibaqtzmL7V949Ac,20839
21
21
  prefect/task_engine.py,sha256=_2I7XLwoT_nNhpzTMa_52aQKjsDoaW6WpzwIHYEWZS0,2598
22
22
  prefect/task_runners.py,sha256=HXUg5UqhZRN2QNBqMdGE1lKhwFhT8TaRN75ScgLbnw8,11012
@@ -39,10 +39,11 @@ prefect/_internal/concurrency/primitives.py,sha256=kxCPD9yLtCeqt-JIHjevL4Zt5FvrF
39
39
  prefect/_internal/concurrency/services.py,sha256=aggJd4IUSB6ufppRYdRT-36daEg1JSpJCvK635R8meg,11951
40
40
  prefect/_internal/concurrency/threads.py,sha256=-tReWZL9_XMkRS35SydAfeePH2vqCqb1CGM8lgrKT1I,7846
41
41
  prefect/_internal/concurrency/waiters.py,sha256=DXTD_bbVEUhcTplYQFX8mGmL6nsqJGEDfvS0TmHmIQk,9475
42
- prefect/_internal/pydantic/__init__.py,sha256=zhbVYT051zywa0rF7Q62jaVFH2D2no3CTCJ1ZXktmR8,482
43
- prefect/_internal/pydantic/_compat.py,sha256=YTRAmOTTYybXKJtwsPjee40shpWCtAYlI7RZbPADVO0,6532
42
+ prefect/_internal/pydantic/__init__.py,sha256=8kLb8Lq7YIosMYBnzidH9HR-LIZjbBYseuM4rEi0KUI,498
43
+ prefect/_internal/pydantic/_compat.py,sha256=rK54VSquNOX4mPOh5sexiM0q12vxwbxqSbFRKvIn0Jw,7424
44
44
  prefect/_internal/pydantic/schemas.py,sha256=tsRKq5yEIgiRbWMl3BPnbfNaKyDN6pq8WSs0M8SQMm4,452
45
- prefect/_internal/pydantic/v2_schema.py,sha256=fySqjMCFoJpRs7wN6c5qoVKePbDbWcXYUoYOs5eFzL0,3485
45
+ prefect/_internal/pydantic/v1_schema.py,sha256=j_DDQqpP1xFsvkNSjWeviTnnFyNPPqou9n4M2lf3K2U,1133
46
+ prefect/_internal/pydantic/v2_schema.py,sha256=RE7VQaf6nefhdYU2O-gbzumMcuBk-fiH_6Rq9F7eAqg,3689
46
47
  prefect/_internal/pydantic/v2_validated_func.py,sha256=44I4o8jjiS7TYep-E6UYMwjpYH5F1WwJFajW81A3wts,3823
47
48
  prefect/_internal/pydantic/annotations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
49
  prefect/_internal/pydantic/annotations/pendulum.py,sha256=rWT6zzCtIqvK2_EuAkMt73ZzAvdE5tF2104e0-tIaa4,2625
@@ -140,7 +141,7 @@ prefect/blocks/system.py,sha256=Nlp-3315Hye3FJ5uhDovSPGBIEKi5UbCkAcy3hDxhKk,3057
140
141
  prefect/blocks/webhook.py,sha256=hhyWck7mAPfD_12bl40dJedNC9HIaqs7z13iYcZZ14o,2005
141
142
  prefect/client/__init__.py,sha256=yJ5FRF9RxNUio2V_HmyKCKw5G6CZO0h8cv6xA_Hkpcc,477
142
143
  prefect/client/base.py,sha256=VsJWgaSEyIbHo2MfIkBuErahYwXnU68P3R-n83jx2LI,15211
143
- prefect/client/cloud.py,sha256=rrxwmYE9yH4HIewu-xG0HY4P7rwP9gFNitBMYQybcvE,3998
144
+ prefect/client/cloud.py,sha256=Ozf-jklZntlzOIKKlAh2YW4eJKgTsd1ln3W9N3xO5w4,4052
144
145
  prefect/client/collections.py,sha256=I9EgbTg4Fn57gn8vwP_WdDmgnATbx9gfkm2jjhCORjw,1037
145
146
  prefect/client/constants.py,sha256=Z_GG8KF70vbbXxpJuqW5pLnwzujTVeHbcYYRikNmGH0,29
146
147
  prefect/client/orchestration.py,sha256=HnBg-i5vrbzhn0KaXgJDbGST5KDsmEv5oJFyWDemHZ0,111199
@@ -226,7 +227,7 @@ prefect/software/python.py,sha256=reuEJFZPJ5PrDMfK3BuPpYieHNkOXJAyCAaopQcjDqE,17
226
227
  prefect/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
227
228
  prefect/utilities/annotations.py,sha256=p33yhh1Zx8BZUlTtl8gKRbpwWU9FVnZ8cfYrcd5KxDI,3103
228
229
  prefect/utilities/asyncutils.py,sha256=dNVKZKLVdNOhQObPf-224l3uWyKnt1jSFpReMpWFwT4,15674
229
- prefect/utilities/callables.py,sha256=5G2K_ZAnNoWoY7DqESKpbf4ltF5fkGRlJUvDwBGD7t0,11603
230
+ prefect/utilities/callables.py,sha256=seO853HYt7gXl2-tHZMM_7rrXrvsAxk9qwzJ89UN8_E,11647
230
231
  prefect/utilities/collections.py,sha256=D_DT489rTCwyzZb021i0xp8osBkkQgSW9XLOoLBzgkg,15436
231
232
  prefect/utilities/compat.py,sha256=mNQZDnzyKaOqy-OV-DnmH_dc7CNF5nQgW_EsA4xMr7g,906
232
233
  prefect/utilities/context.py,sha256=nb_Kui1q9cYK5fLy84baoBzko5-mOToQkd1AnZhwyq8,418
@@ -247,7 +248,7 @@ prefect/utilities/text.py,sha256=eXGIsCcZ7h_6hy8T5GDQjL8GiKyktoOqavYub0QjgO4,445
247
248
  prefect/utilities/validation.py,sha256=60AseIr0F1XlygAuqweswz288i7YP4LlLY00s1dM2cg,1985
248
249
  prefect/utilities/visualization.py,sha256=iGkYtroroYY9Rsiw1ok1bLv9FwsNyjtiK-0vBPL-ZWI,6491
249
250
  prefect/utilities/schema_tools/__init__.py,sha256=YtbTThhL8nPEYm3ByTHeOLcj2fm8fXrsxB-ioBWoIek,284
250
- prefect/utilities/schema_tools/hydration.py,sha256=SS53N9afZHWT7enJND3Hwnl6vdSnvr-SrJIYKvV_F-o,5823
251
+ prefect/utilities/schema_tools/hydration.py,sha256=tonsuKKmjnPnqzFTx441y9g3nhziiWlDesYJqezEmCQ,6181
251
252
  prefect/utilities/schema_tools/validation.py,sha256=b4ZsyrUlU7riaQP9NMQ6FlayzG46SrSE7pKGNCFWscM,7974
252
253
  prefect/workers/__init__.py,sha256=6el2Q856CuRPa5Hdrbm9QyAWB_ovcT2bImSFsoWI46k,66
253
254
  prefect/workers/base.py,sha256=7K1D7Dyls0tMpT1ATsfzbq5BP96j15spjTM_OEmXuXM,44644
@@ -255,8 +256,8 @@ prefect/workers/block.py,sha256=lvKlaWdA-DCCXDX23HHK9M5urEq4x2wmpKtU9ft3a7k,7767
255
256
  prefect/workers/process.py,sha256=Kxj_eZYh6R8t8253LYIIafiG7dodCF8RZABwd3Ng_R0,10253
256
257
  prefect/workers/server.py,sha256=WVZJxR8nTMzK0ov0BD0xw5OyQpT26AxlXbsGQ1OrxeQ,1551
257
258
  prefect/workers/utilities.py,sha256=VfPfAlGtTuDj0-Kb8WlMgAuOfgXCdrGAnKMapPSBrwc,2483
258
- prefect_client-2.16.5.dist-info/LICENSE,sha256=MCxsn8osAkzfxKC4CC_dLcUkU8DZLkyihZ8mGs3Ah3Q,11357
259
- prefect_client-2.16.5.dist-info/METADATA,sha256=A58u55jaNnt77urHhD1faDHXMlL8cClM78JMOFrLwhw,7349
260
- prefect_client-2.16.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
261
- prefect_client-2.16.5.dist-info/top_level.txt,sha256=MJZYJgFdbRc2woQCeB4vM6T33tr01TmkEhRcns6H_H4,8
262
- prefect_client-2.16.5.dist-info/RECORD,,
259
+ prefect_client-2.16.6.dist-info/LICENSE,sha256=MCxsn8osAkzfxKC4CC_dLcUkU8DZLkyihZ8mGs3Ah3Q,11357
260
+ prefect_client-2.16.6.dist-info/METADATA,sha256=gQMvNiYP2z2uOjBfNBMfpNTrVgef3llB2bD4MWMGyAQ,7349
261
+ prefect_client-2.16.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
262
+ prefect_client-2.16.6.dist-info/top_level.txt,sha256=MJZYJgFdbRc2woQCeB4vM6T33tr01TmkEhRcns6H_H4,8
263
+ prefect_client-2.16.6.dist-info/RECORD,,