fix(pydantic): improve error message for untyped state parameter#614
Merged
skrawcz merged 1 commit intoapache:mainfrom Dec 31, 2025
Merged
Conversation
When a pydantic_action function has a 'state' parameter without type annotation, raise a clear ValueError explaining that the parameter must be annotated with a pydantic.BaseModel subclass, instead of a cryptic KeyError. Closes apache#385 Signed-off-by: majiayu000 <1835304752@qq.com>
skrawcz
reviewed
Dec 30, 2025
| "a type annotation of a type extending: pydantic.BaseModel. Got parameter " | ||
| "state: {state_model.__qualname__}." | ||
| "The 'state' parameter must be annotated with a type extending pydantic.BaseModel. " | ||
| f"Got: {state_model}." |
Contributor
There was a problem hiding this comment.
can you show a before and after example here to help understand the change here please?
skrawcz
reviewed
Dec 30, 2025
Contributor
skrawcz
left a comment
There was a problem hiding this comment.
looks good. would love a before and after to show case it.
Contributor
Author
Before and After ExampleBefore (without this fix)from burr.integrations.pydantic import pydantic_action
@pydantic_action
def my_action(state): # missing type annotation
return stateError: This error is cryptic and doesn't tell the user what went wrong. After (with this fix)from burr.integrations.pydantic import pydantic_action
@pydantic_action
def my_action(state): # missing type annotation
return stateError: Now the error message clearly explains what the user needs to fix. |
skrawcz
approved these changes
Dec 31, 2025
Contributor
|
Great thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
type_hints["state"]totype_hints.get("state")to avoid KeyErrorTest plan
_fn_with_untyped_state_argand parameterized test casetest__validate_and_extract_signature_types_untyped_state_error_messageto verify error messageCloses #385