Getting Pydantic error when trying to create StateCreate object (used by state.to_state_create()):
pydantic.errors.PydanticUserError:StateCreateis not fully defined; you should define all referenced types, then callStateCreate.model_rebuild().
Version: 3.0.4
API version: 0.8.4
Python version: 3.11.6
Git commit: c068d7e2
Built: Tue, Oct 1, 2024 11:54 AM
OS/Arch: linux/x86_64
Profile: local
Server type: server
Pydantic version: 2.9.2
Integrations:
prefect-kubernetes: 0.5.0
(Was tested with prefect versions 3.0.3,3.0.6 and 3.0.7 as well)
Additional context
In the actions.py the following exist:
if TYPE_CHECKING: # = False
from prefect.results import BaseResult, ResultRecordMetadata
R = TypeVar("R")
class StateCreate(ActionBaseModel):
"""Data used by the Prefect REST API to create a new state."""
type: StateType
name: Optional[str] = Field(default=None)
message: Optional[str] = Field(default=None, examples=["Run started"])
state_details: StateDetails = Field(default_factory=StateDetails)
data: Union["BaseResult[R]", "ResultRecordMetadata", Any] = Field( # The classes were not imported so pydantic failed
default=None,
)
when changed TYPE_CHECKING=TRUE, the entire import of the prefect library fails:
ImportError: cannot import name 'DEFAULT_BLOCK_SCHEMA_VERSION' from partially initialized module 'prefect.client.schemas' (most likely due to a circular import) (/workspaces/prefect-poc/.venv/lib/python3.11/site-packages/prefect/client/schemas/__init__.py)
Every thing worked for me when changed the class definition to:
class StateCreate(ActionBaseModel):
"""Data used by the Prefect REST API to create a new state."""
type: StateType
name: Optional[str] = Field(default=None)
message: Optional[str] = Field(default=None, examples=["Run started"])
state_details: StateDetails = Field(default_factory=StateDetails)
data: Union[Any] = Field(
default=None,
)
Bug summary
Getting Pydantic error when trying to create StateCreate object (used by
state.to_state_create()
):pydantic.errors.PydanticUserError:
StateCreateis not fully defined; you should define all referenced types, then call
StateCreate.model_rebuild().
User level code that fails:
Version info (
prefect version
output)Additional context
In the actions.py the following exist:
when changed TYPE_CHECKING=TRUE, the entire import of the prefect library fails:
Every thing worked for me when changed the class definition to: