burr icon indicating copy to clipboard operation
burr copied to clipboard

pydantic: uninformative error

Open zilto opened this issue 4 months ago • 1 comments

I'm building an application with burr.integrations.pydantic and building the graph + application fails. The following error message isn't helpful because it exposes internal implementation (i.e., the key "state" is nowhere in my code.

Traceback (most recent call last):
  File "/home/tjean/projects/form_helper/app.py", line 45, in <module>
    @pydantic_action(reads=["form"], writes=["current_field"])
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tjean/projects/form_helper/.venv/lib/python3.11/site-packages/burr/integrations/pydantic.py", line 180, in decorator
    itype, otype = _validate_and_extract_signature_types(fn)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tjean/projects/form_helper/.venv/lib/python3.11/site-packages/burr/integrations/pydantic.py", line 116, in _validate_and_extract_signature_types
    if (state_model := type_hints["state"]) is inspect.Parameter.empty or not issubclass(
                       ~~~~~~~~~~^^^^^^^^^
KeyError: 'state'

The only hint is to look at "line 45", but I can't tell what's the issue. I ended up finding that the issue is the function signature on line 46.

Original:

@pydantic_action(reads=["form"], writes=["current_field"])
def prompt_user(state):

Fix:

@pydantic_action(reads=["form"], writes=["current_field"])
def prompt_user(state: BurrState):

zilto avatar Oct 03 '24 14:10 zilto