10000 Fix `pydantic` deprecation warnings (#17698) · CodersSampling/prefect@baf0af1 · GitHub
[go: up one dir, main page]

Skip to content

Commit baf0af1

Browse files
authored
Fix pydantic deprecation warnings (PrefectHQ#17698)
1 parent 6d9e854 commit baf0af1

File tree

21 files changed

+1766
-1395
lines changed

21 files changed

+1766
-1395
lines changed

docs/v3/api-ref/rest-api/server/schema.json

Lines changed: 150 additions & 14 deletions
Large diffs are not rendered by default.

docs/v3/api-ref/settings-ref.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ The number of seconds to wait before retrying when a task run cannot secure a co
22472247
**Default**: `30`
22482248

22492249
**Constraints**:
2250-
- Minimum: 0.0
2250+
- Minimum: 0
22512251

22522252
**TOML dotted key path**: `server.tasks.tag_concurrency_slot_wait_seconds`
22532253

schemas/settings.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@
19881988
"tag_concurrency_slot_wait_seconds": {
19891989
"default": 30,
19901990
"description": "The number of seconds to wait before retrying when a task run cannot secure a concurrency slot from the server.",
1991-
"minimum": 0.0,
1991+
"minimum": 0,
19921992
"supported_environment_variables": [
19931993
"PREFECT_SERVER_TASKS_TAG_CONCURRENCY_SLOT_WAIT_SECONDS",
19941994
"PREFECT_TASK_RUN_TAG_CONCURRENCY_SLOT_WAIT_SECONDS"

src/prefect/_internal/compatibility/deprecated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def __init__(__pydantic_self__: M, **data: Any) -> None:
255255

256256
cls_init(__pydantic_self__, **data)
257257

258-
field = __pydantic_self__.model_fields.get(name)
258+
field = __pydantic_self__.__class__.model_fields.get(name)
259259
if field is not None:
260260
json_schema_extra = field.json_schema_extra or {}
261261

src/prefect/_internal/pydantic/v2_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ def create_v2_schema(
106106
# ensure backwards compatibility by copying $defs into definitions
107107
if "$defs" in schema:
108108
schema["definitions"] = schema["$defs"]
109+
109110
return schema

src/prefect/blocks/core.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Optional,
1919
TypeVar,
2020
Union,
21+
cast,
2122
get_origin,
2223
)
2324
from uuid import UUID, uuid4
@@ -169,14 +170,13 @@ def _collect_secret_fields(
169170
return
170171

171172
if type_ in (SecretStr, SecretBytes) or (
172-
isinstance(type_, type)
173+
isinstance(type_, type) # type: ignore[unnecessaryIsInstance]
173174
and getattr(type_, "__module__", None) == "pydantic.types"
174175
and getattr(type_, "__name__", None) == "Secret"
175176
):
176177
secrets.append(name)
177178
elif type_ == SecretDict:
178-
# Append .* to field name to signify that all values under this
179-
# field are secret and should be obfuscated.
179+
# Append .* to field name to signify that all values under a given key are secret and should be obfuscated.
180180
secrets.append(f"{name}.*")
181181
elif Block.is_block_class(type_):
182182
secrets.extend(
@@ -1501,14 +1501,7 @@ def model_json_schema(
15011501
if "$defs" in schema:
15021502
schema["definitions"] = schema.pop("$defs")
15031503

1504-
# we aren't expecting these additional fields in the schema
1505-
if "additionalProperties" in schema:
1506-
schema.pop("additionalProperties")
1507-
1508-
for _, definition in schema.get("definitions", {}).items():
1509-
if "additionalProperties" in defini 10000 tion:
1510-
definition.pop("additionalProperties")
1511-
1504+
schema = remove_nested_keys(["additionalProperties"], schema)
15121505
return schema
15131506

15141507
@classmethod
@@ -1521,6 +1514,7 @@ def model_validate(
15211514
context: dict[str, Any] | None = None,
15221515
) -> Self:
15231516
if isinstance(obj, dict):
1517+
obj = cast(dict[str, Any], obj)
15241518
extra_serializer_fields = {
15251519
"_block_document_id",
15261520
"_block_document_name",
@@ -1530,7 +1524,10 @@ def model_validate(
15301524
obj.pop(field, None)
15311525

15321526
return super().model_validate(
1533-
obj, strict=strict, from_attributes=from_attributes, context=context
1527+
obj,
1528+
strict=strict,
1529+
from_attributes=from_attributes,
1530+
context=context,
15341531
)
15351532

15361533
def model_dump(

src/prefect/flows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ def resolve_block_reference(data: Any | dict[str, Any]) -> Any:
636636
cast_parameters = {
637637
k: v
638638
for k, v in dict(iter(model)).items()
639-
if k in model.model_fields_set or model.model_fields[k].default_factory
639+
if k in model.model_fields_set
640+
or type(model).model_fields[k].default_factory
640641
}
641642
return cast_parameters
642643

src/prefect/server/api/flow_runs.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ async def update_flow_run(
181181

182182
@router.post("/count")
183183
async def count_flow_runs(
184-
flows: schemas.filters.FlowFilter = None,
185-
flow_runs: schemas.filters.FlowRunFilter = None,
186-
task_runs: schemas.filters.TaskRunFilter = None,
187-
deployments: schemas.filters.DeploymentFilter = None,
188-
work_pools: schemas.filters.WorkPoolFilter = None,
189-
work_pool_queues: schemas.filters.WorkQueueFilter = None,
184+
flows: Optional[schemas.filters.FlowFilter] = None,
185+
flow_runs: Optional[schemas.filters.FlowRunFilter] = None,
186+
task_runs: Optional[schemas.filters.TaskRunFilter] = None,
187+
deployments: Optional[schemas.filters.DeploymentFilter] = None,
188+
work_pools: Optional[schemas.filters.WorkPoolFilter] = None,
189+
work_pool_queues: Optional[schemas.filters.WorkQueueFilter] = None,
190190
db: PrefectDBInterface = Depends(provide_database_interface),
191191
) -> int:
192192
"""
@@ -279,12 +279,12 @@ async def flow_run_history(
279279
json_schema_extra={"format": "time-delta"},
280280
alias="history_interval_seconds",
281281
),
282-
flows: schemas.filters.FlowFilter = None,
283-
flow_runs: schemas.filters.FlowRunFilter = None,
284-
task_runs: schemas.filters.TaskRunFilter = None,
285-
deployments: schemas.filters.DeploymentFilter = None,
286-
work_pools: schemas.filters.WorkPoolFilter = None,
287-
work_queues: schemas.filters.WorkQueueFilter = None,
282+
flows: Optional[schemas.filters.FlowFilter] = None,
283+
flow_runs: Optional[schemas.filters.FlowRunFilter] = None,
284+
task_runs: Optional[schemas.filters.TaskRunFilter] = None,
285+
deployments: Optional[schemas.filters.DeploymentFilter] = None,
286+
work_pools: Optional[schemas.filters.WorkPoolFilter] = None,
287+
work_queues: Optional[schemas.filters.WorkQueueFilter] = None,
288288
db: PrefectDBInterface = Depends(provide_database_interface),
289289
) -> List[schemas.responses.HistoryResponse]:
290290
"""
@@ -293,6 +293,7 @@ async def flow_run_history(
293293
if isinstance(history_interval, float):
294294
history_interval = datetime.timedelta(seconds=history_interval)
295295

296+
assert isinstance(history_interval, datetime.timedelta)
296297
if history_interval < datetime.timedelta(seconds=1):
297298
raise HTTPException(
298299
status.HTTP_422_UNPROCESSABLE_ENTITY,
@@ -351,8 +352,8 @@ async def read_flow_run_graph_v1(
351352
@router.get("/{id:uuid}/graph-v2", tags=["Flow Run Graph"])
352353
async def read_flow_run_graph_v2(
353354
flow_run_id: UUID = Path(..., description="The flow run id", alias="id"),
354-
since: DateTime = Query(
355-
default=jsonable_encoder(DateTime.min),
355+
since: datetime.datetime = Query(
356+
default=jsonable_encoder(datetime.datetime.min),
356357
description="Only include runs that start or end after this time.",
357358
),
358359
db: PrefectDBInterface = Depends(provide_database_interface),

src/prefect/server/api/run_history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def run_history(
3636
deployments: Optional[schemas.filters.DeploymentFilter] = None,
3737
work_pools: Optional[schemas.filters.WorkPoolFilter] = None,
3838
work_queues: Optional[schemas.filters.WorkQueueFilter] = None,
39-
) -> List[schemas.responses.HistoryResponse]:
39+
) -> list[schemas.responses.HistoryResponse]:
4040
"""
4141
Produce a history of runs aggregated by interval and state
4242
"""

src/prefect/settings/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def to_environment_variables(
134134
def ser_model(
135135
self, handler: SerializerFunctionWrapHandler, info: SerializationInfo
136136
) -> Any:
137-
jsonable_self = handler(self)
137+
jsonable_self: dict[str, Any] = handler(self)
138138
# iterate over fields to ensure child models that have been updated are also included
139139
for key in type(self).model_fields.keys():
140140
if info.exclude and key in info.exclude 378D :

0 commit comments

Comments
 (0)
0