Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JSON schema migration to require id, created, and updated on responses #16391

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ repos:
src/prefect/server/api/.*|
src/prefect/server/schemas/.*|
src/prefect/server/events/.*|
src/prefect/server/utilities/schemas/.*|
ui-v2/package.json
)$
pass_filenames: false
124 changes: 99 additions & 25 deletions docs/v3/api-ref/rest-api/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9904,6 +9904,7 @@
}
},
"type": "object",
"required": [],
"title": "Artifact"
},
"ArtifactCollection": {
Expand Down Expand Up @@ -10030,7 +10031,10 @@
"type": "object",
"required": [
"key",
"latest_id"
"latest_id",
"id",
"created",
"updated"
],
"title": "ArtifactCollection"
},
Expand Down Expand Up @@ -10896,7 +10900,10 @@
"required": [
"name",
"trigger",
"actions"
"actions",
"id",
"created",
"updated"
],
"title": "Automation"
},
Expand Down Expand Up @@ -11557,7 +11564,10 @@
"type": "object",
"required": [
"block_schema_id",
"block_type_id"
"block_type_id",
"id",
"created",
"updated"
],
"title": "BlockDocument",
"description": "An ORM representation of a block document."
Expand Down Expand Up @@ -11899,7 +11909,10 @@
"type": "object",
"required": [
"checksum",
"block_type_id"
"block_type_id",
"id",
"created",
"updated"
],
"title": "BlockSchema",
"description": "An ORM representation of a block schema."
Expand Down Expand Up @@ -12203,7 +12216,10 @@
"type": "object",
"required": [
"name",
"slug"
"slug",
"id",
"created",
"updated"
],
"title": "BlockType",
"description": "An ORM representation of a block type"
Expand Down Expand Up @@ -14627,7 +14643,10 @@
"type": "object",
"required": [
"tag",
"concurrency_limit"
"concurrency_limit",
"id",
"created",
"updated"
],
"title": "ConcurrencyLimit",
"description": "An ORM representation of a concurrency limit."
Expand Down Expand Up @@ -14739,7 +14758,10 @@
"type": "object",
"required": [
"name",
"limit"
"limit",
"id",
"created",
"updated"
],
"title": "ConcurrencyLimitV2",
"description": "An ORM representation of a v2 concurrency limit."
Expand Down Expand Up @@ -15101,7 +15123,10 @@
"required": [
"token",
"client",
"expiration"
"expiration",
"id",
"created",
"updated"
],
"title": "CsrfToken"
},
Expand Down Expand Up @@ -16260,7 +16285,10 @@
"type": "object",
"required": [
"name",
"flow_id"
"flow_id",
"id",
"created",
"updated"
],
"title": "DeploymentResponse"
},
Expand Down Expand Up @@ -16345,7 +16373,10 @@
},
"type": "object",
"required": [
"schedule"
"schedule",
"id",
"created",
"updated"
],
"title": "DeploymentSchedule"
},
Expand Down Expand Up @@ -17345,7 +17376,10 @@
},
"type": "object",
"required": [
"name"
"name",
"id",
"created",
"updated"
],
"title": "Flow",
"description": "An ORM representation of flow data."
Expand Down Expand Up @@ -18034,7 +18068,10 @@
},
"type": "object",
"required": [
"flow_id"
"flow_id",
"id",
"created",
"updated"
],
"title": "FlowRun",
"description": "An ORM representation of flow run data."
Expand Down Expand Up @@ -19069,7 +19106,10 @@
"required": [
"flow_run_id",
"key",
"value"
"value",
"id",
"created",
"updated"
],
"title": "FlowRunInput"
},
Expand Down Expand Up @@ -19152,7 +19192,10 @@
"required": [
"state_names",
"tags",
"block_document_id"
"block_document_id",
"id",
"created",
"updated"
],
"title": "FlowRunNotificationPolicy",
"description": "An ORM representation of a flow run notification."
Expand Down Expand Up @@ -19854,7 +19897,10 @@
},
"type": "object",
"required": [
"flow_id"
"flow_id",
"id",
"created",
"updated"
],
"title": "FlowRunResponse"
},
Expand Down Expand Up @@ -20036,7 +20082,10 @@
"required": [
"name",
"limit",
"active_slots"
"active_slots",
"id",
"created",
"updated"
],
"title": "GlobalConcurrencyLimitResponse",
"description": "A response object for global concurrency limits."
Expand Down Expand Up @@ -20411,7 +20460,10 @@
"name",
"level",
"message",
"timestamp"
"timestamp",
"id",
"created",
"updated"
],
"title": "Log",
"description": "An ORM representation of log data."
Expand Down Expand Up @@ -21428,7 +21480,10 @@
},
"type": "object",
"required": [
"name"
"name",
"id",
"created",
"updated"
],
"title": "SavedSearch",
"description": "An ORM representation of saved search data. Represents a set of filter criteria."
Expand Down Expand Up @@ -21783,7 +21838,8 @@
},
"type": "object",
"required": [
"type"
"type",
"id"
],
"title": "State",
"description": "Represents the state of a run."
Expand Down Expand Up @@ -22466,7 +22522,10 @@
"type": "object",
"required": [
"task_key",
"dynamic_key"
"dynamic_key",
"id",
"created",
"updated"
],
"title": "TaskRun",
"description": "An ORM representation of task run data."
Expand Down Expand Up @@ -23419,7 +23478,10 @@
"type": "object",
"required": [
"name",
"value"
"value",
"id",
"created",
"updated"
],
"title": "Variable"
},
Expand Down Expand Up @@ -23836,7 +23898,10 @@
"type": "object",
"required": [
"name",
"type"
"type",
"id",
"created",
"updated"
],
"title": "WorkPool",
"description": "An ORM representation of a work pool"
Expand Down Expand Up @@ -24196,7 +24261,10 @@
},
"type": "object",
"required": [
"name"
"name",
"id",
"created",
"updated"
],
"title": "WorkQueue",
"description": "An ORM representation of a work queue"
Expand Down Expand Up @@ -24556,7 +24624,10 @@
},
"type": "object",
"required": [
"name"
"name",
"id",
"created",
"updated"
],
"title": "WorkQueueResponse"
},
Expand Down Expand Up @@ -24892,7 +24963,10 @@
"type": "object",
"required": [
"name",
"work_pool_id"
"work_pool_id",
"id",
"created",
"updated"
],
"title": "WorkerResponse"
},
Expand Down
25 changes: 24 additions & 1 deletion src/prefect/server/utilities/schemas/bases.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import datetime
import os
from abc import ABC, abstractmethod
from functools import partial
from typing import TYPE_CHECKING, Any, ClassVar, Optional, TypeVar
from uuid import UUID, uuid4

import pendulum
from pydantic import BaseModel, ConfigDict, Field
from pydantic.config import JsonDict
from typing_extensions import Self

from prefect.types import DateTime
Expand Down Expand Up @@ -181,13 +183,29 @@ def model_dump_for_orm(
return deep


def _ensure_fields_required(field_names: list[str], schema: JsonDict) -> None:
for field_name in field_names:
if "required" not in schema:
schema["required"] = []
if (
(required := schema.get("required"))
and isinstance(required, list)
and field_name not in required
):
required.append(field_name)


class IDBaseModel(PrefectBaseModel):
"""
A PrefectBaseModel with an auto-generated UUID ID value.

The ID is reset on copy() and not included in equality comparisons.
"""

model_config = ConfigDict(
json_schema_extra=partial(_ensure_fields_required, ["id"])
)

_reset_fields: ClassVar[set[str]] = {"id"}
id: UUID = Field(default_factory=uuid4)

Expand All @@ -203,7 +221,12 @@ class ORMBaseModel(IDBaseModel):

_reset_fields: ClassVar[set[str]] = {"id", "created", "updated"}

model_config = ConfigDict(from_attributes=True)
model_config = ConfigDict(
from_attributes=True,
json_schema_extra=partial(
_ensure_fields_required, ["id", "created", "updated"]
),
)

created: Optional[DateTime] = Field(default=None, repr=False)
updated: Optional[DateTime] = Field(default=None, repr=False)
Expand Down
2 changes: 1 addition & 1 deletion ui-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"format:check": "biome check",
"format": "biome check --write",
"preview": "vite preview",
"service-sync": "uv run ../scripts/generate_oss_openapi_schema.py && npx openapi-typescript oss_schema.json -o src/api/prefect.ts && rm oss_schema.json",
"service-sync": "uv run --with-editable ../. ../scripts/generate_oss_openapi_schema.py && npx openapi-typescript oss_schema.json -o src/api/prefect.ts && rm oss_schema.json",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
Expand Down
Loading
Loading