fasthtml
fasthtml copied to clipboard
[BUG] KeyError raised if request is missing an expected param
Describe the bug
A KeyError is raised whenever a request is made that is missing an expected param. This happens if the expected param is defined with or without a default value.
Minimal Reproducible Example Here's a minimal app.
from fasthtml.common import *
app,rt = fast_app(default_hdrs=False)
@rt
def check(p1:str='', p2:str=''): return Response(status_code=200)
serve(port=5000)
Here's some test code
import httpx
r = httpx.post('http://localhost:5000/check', json={'p1': 'val'}, headers={'Content-Type': 'application/json'})
print(r.status_code)
Running the test triggers KeyError: 'p2' and r has a 500 status code.
Expected behavior
A KeyError should not be raised if a param is missing.
Environment Information Please provide the following version information:
- fastlite version: 0.1.2
- fastcore version: 1.8.0
- fasthtml version: 0.12.5
Confirmation Please confirm the following:
- [x] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
- [x] I have provided a minimal reproducible example
- [x] I have included the versions of fastlite, fastcore, and fasthtml
- [x] I understand that this is a volunteer open source project with no commercial support.
Additional context N/A
Screenshots N/A