fix input validator type#2986
Conversation
|
@szvsw is attempting to deploy a commit to the Hatchet Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Updates the Python SDK to correct the exposed type of BaseWorkflow.input_validator (it is a Pydantic TypeAdapter at runtime) and adds a separate accessor for the underlying validator type, along with a patch version bump and changelog entry.
Changes:
- Bump Python SDK version to
1.23.1. - Fix
BaseWorkflow.input_validatorproperty typing toTypeAdapter[...]and addinput_validator_type. - Document the change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sdks/python/pyproject.toml |
Patch version bump for the Python SDK release. |
sdks/python/hatchet_sdk/runnables/workflow.py |
Corrects input_validator typing and adds an accessor for the underlying type. |
sdks/python/CHANGELOG.md |
Adds release notes describing the typing fix and new properties. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @property | ||
| def input_validator(self) -> type[TWorkflowInput]: | ||
| return cast(type[TWorkflowInput], self.config.input_validator) | ||
| def input_validator(self) -> TypeAdapter[TWorkflowInput]: | ||
| return cast(TypeAdapter[TWorkflowInput], self.config.input_validator) | ||
|
|
||
| @property | ||
| def input_validator_type(self) -> type[TWorkflowInput]: | ||
| return cast(type[TWorkflowInput], self.config.input_validator._type) |
There was a problem hiding this comment.
A regression test would help prevent this typing/behavior issue from reappearing: add a unit test that constructs a workflow with a custom input_validator and asserts that workflow.input_validator is a TypeAdapter and that workflow.input_validator_type returns the original validator class (and also cover the default EmptyModel case).
| return cast(type[TWorkflowInput], self.config.input_validator._type) | ||
|
|
There was a problem hiding this comment.
input_validator_type accesses self.config.input_validator._type, which is a private Pydantic TypeAdapter attribute and may change across Pydantic versions (and may not be present in type stubs under strict mypy). Consider deriving the underlying type via a public API (e.g., input_validator.core_schema) or storing the normalized validator type alongside the adapter when building WorkflowConfig so this property doesn’t depend on internals.
| return cast(type[TWorkflowInput], self.config.input_validator._type) | |
| schema = self.config.input_validator.core_schema | |
| # For Pydantic model-based validators, the core schema is typically a dict | |
| # with a "cls" entry pointing at the underlying model class. | |
| if isinstance(schema, dict): | |
| cls = schema.get("cls") | |
| if isinstance(cls, type): | |
| return cast(type[TWorkflowInput], cls) | |
| # Fallback: we were unable to determine the type from the public schema. | |
| # Return a broad type while preserving the annotated return type. | |
| return cast(type[TWorkflowInput], Any) |
|
📝 Documentation updates detected! New suggestion: Document input_validator and input_validator_type workflow properties Tip: Configure how Promptless handles changelogs in Agent Settings 📋 |
Description
Fixes an issue introduced in v1.21.0 where the move to using type adapters broke the return type of the
BaseWorkflow.input_validatorclass property method; this method was provided to allow a type checker-friendly way of accessing the input type of a workflow.Solution is to allow a type friendly version of both the type adapter and the type to be provided.
Type of change
What's Changed