Route is missing a parameter a form expected
The error
The route function 'save' expects a value for parameter 'pet_name',
but none was provided.
When the request carried a similar name, the message adds a did-you-mean hint suggesting it.
What it means
The route declares a parameter, and after state injection, form fields, and button arguments were matched up by name, nothing filled it. The route cannot run with a missing argument, so the request stopped.
Where to look
Compare two places side by side: the route's def line, and the
page that submitted to it (the form's components and the button's
arguments). The mismatch is somewhere between those two.
Check
- Names differ: the page has
TextBox("petname")but the route sayspet_name. The did-you-mean hint catches most of these. - The component is missing: the route expects a value, but no input with that name is on the submitting page at all.
- The wrong button: another page's button also targets this route, without the form fields the route needs. Every button that targets a route must be accompanied by whatever inputs the route's parameters require.
- It is actually
state: if the unfilled parameter is your state, make it the first parameter and name itstate.
Fix
Make the names agree; you can change either side:
# The page:
TextBox("pet_name")
Button("Save", "save")
# The route:
@route
def save(state: State, pet_name: str) -> Page:
...
Or, when the value is legitimately optional, give the parameter a
default: def save(state: State, pet_name: str = "").
Confirm
Submit the form again; the route should run. Then call the route in a
test with the values spelled out,
assert_state(save(State(...), "Ada"), State(...)), so a future
rename fails loudly before anyone clicks.
Prevent
Pick one name per piece of information and use it for both the component and the parameter. If you write the form and its route in the same sitting and check each name against its parameter, the mismatch is unlikely to appear in the first place.
Understand
Forms and input explains the name-to-parameter contract this error enforces.