You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query parameter list example in docs throws AssertionError: Query default value cannot be set in Annotated for 'q'. Set the default value with = instead.
#9283
When I try to create a query param that is a list[] but also optional and defaults to a None, I get a "AssertionError: Query default value cannot be set in Annotated for 'q'. Set the default value with = instead" - but as you can see above, the default value is already set using the = syntax.
| app.include_router(courts_table_router, prefix="/table", tags=["table"])
| File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 427, in include_router
| self.router.include_router(
| File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 782, in include_router
| self.add_api_route(
| File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 600, in add_api_route
| route = route_class(
| ^^^^^^^^^^^^
| File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 446, in __init__
| self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/usr/local/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 303, in get_dependant
| type_annotation, depends, param_field = analyze_param(
| ^^^^^^^^^^^^^^
| File "/usr/local/lib/python3.11/site-packages/fastapi/dependencies/utils.py", line 387, in analyze_param
| assert field_info.default is Undefined or field_info.default is Required, (
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| AssertionError: `Query` default value cannot be set in `Annotated` for 'q'. Set the default value with `=` instead.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
When I try to create a query param that is a list[] but also optional and defaults to a None, I get a "AssertionError:
Querydefault value cannot be set inAnnotatedfor 'q'. Set the default value with=instead" - but as you can see above, the default value is already set using the = syntax.I thought this was a problem with my code, but I tried running the example from the fastapi docs here - https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#query-parameter-list-multiple-values and it throws the same error.
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.95.0
Python Version
3.11.2
Additional Context
No response
All reactions