Skip to content

Commit

Permalink
rebuild models
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Dec 9, 2024
1 parent a8c81e0 commit c2420ee
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/prefect/client/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
)
from prefect.events.schemas.automations import Automation


defer_build_cfg = ConfigDict(defer_build=True)

BlockTypeAdapter = TypeAdapter("BlockType", config=defer_build_cfg)
# Create the adapters with forward refs
BlockTypeAdapter: TypeAdapter["BlockType"] = TypeAdapter(
"BlockType", config=defer_build_cfg
)
BlockSchemaAdapter = TypeAdapter(List["BlockSchema"], config=defer_build_cfg)
ConcurrencyLimitAdapter = TypeAdapter("ConcurrencyLimit", config=defer_build_cfg)
ConcurrencyLimitListAdapter = TypeAdapter(
Expand All @@ -53,9 +55,6 @@
BlockDocumentListAdapter = TypeAdapter(List["BlockDocument"], config=defer_build_cfg)
BlockSchemaListAdapter = TypeAdapter(List["BlockSchema"], config=defer_build_cfg)
BlockTypeListAdapter = TypeAdapter(List["BlockType"], config=defer_build_cfg)
ConcurrencyLimitListAdapter = TypeAdapter(
List["ConcurrencyLimit"], config=defer_build_cfg
)
DeploymentResponseListAdapter = TypeAdapter(
List["DeploymentResponse"], config=defer_build_cfg
)
Expand Down
8 changes: 8 additions & 0 deletions src/prefect/client/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
FlowRunPolicy,
Log,
Parameter,
State,
TaskRunPolicy,
TaskRunResult,
Variable,
Expand Down Expand Up @@ -140,6 +141,7 @@
from prefect.events import filters
from prefect.events.schemas.automations import Automation, AutomationCore
from prefect.logging import get_logger
from prefect.results import BaseResult, ResultRecordMetadata
from prefect.settings import (
PREFECT_API_DATABASE_CONNECTION_URL,
PREFECT_API_ENABLE_HTTP2,
Expand Down Expand Up @@ -173,6 +175,12 @@
T = TypeVar("T")


BaseResult.model_rebuild()
ResultRecordMetadata.model_rebuild()

State.model_rebuild()


@overload
def get_client(
*,
Expand Down
6 changes: 3 additions & 3 deletions src/prefect/deployments/flow_runs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import TYPE_CHECKING, Iterable, Optional, Union
from typing import TYPE_CHECKING, Any, Iterable, Optional, Union
from uuid import UUID

import anyio
Expand Down Expand Up @@ -35,7 +35,7 @@
async def run_deployment(
name: Union[str, UUID],
client: Optional["PrefectClient"] = None,
parameters: Optional[dict] = None,
parameters: Optional[dict[str, Any]] = None,
scheduled_time: Optional[datetime] = None,
flow_run_name: Optional[str] = None,
timeout: Optional[float] = None,
Expand All @@ -44,7 +44,7 @@ async def run_deployment(
idempotency_key: Optional[str] = None,
work_queue_name: Optional[str] = None,
as_subflow: Optional[bool] = True,
job_variables: Optional[dict] = None,
job_variables: Optional[dict[str, Any]] = None,
) -> "FlowRun":
"""
Create a flow run for a deployment and return it after completion or a timeout.
Expand Down
10 changes: 4 additions & 6 deletions src/prefect/server/events/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from prefect.server.events.schemas.events import Event, ReceivedEvent
from prefect.server.events.services import event_persister
from prefect.server.services import task_run_recorder
Expand All @@ -8,8 +6,8 @@

class EventsPipeline:
@staticmethod
def events_to_messages(events) -> List[MemoryMessage]:
messages = []
def events_to_messages(events: list[Event]) -> list[MemoryMessage]:
messages: list[MemoryMessage] = []
for event in events:
received_event = ReceivedEvent(**event.model_dump())
message = MemoryMessage(
Expand All @@ -19,11 +17,11 @@ def events_to_messages(events) -> List[MemoryMessage]:
messages.append(message)
return messages

async def process_events(self, events: List[Event]):
async def process_events(self, events: list[Event]):
messages = self.events_to_messages(events)
await self.process_messages(messages)

async def process_messages(self, messages: List[MemoryMessage]):
async def process_messages(self, messages: list[MemoryMessage]):
for message in messages:
await self.process_message(message)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_task_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,14 +573,16 @@ async def second():

async def test_task_run_states(
self,
prefect_client,
prefect_client: PrefectClient,
events_pipeline,
):
@task
async def foo():
return TaskRunContext.get().task_run.id
assert (ctx := TaskRunContext.get()) is not None
return ctx.task_run.id

task_run_id = await run_task_async(foo)
assert isinstance(task_run_id, UUID)
await events_pipeline.process_events()
states = await prefect_client.read_task_run_states(task_run_id)

Expand Down

0 comments on commit c2420ee

Please sign in to comment.