MRE
@depends
def with_test():
pass
@app.get("/test", status_code=status.HTTP_204_NO_CONTENT)
@with_test
async def test() -> None:
pass
Error:
File ".venv\Lib\site-packages\fastapi\routing.py", line 757, in __init__
assert is_body_allowed_for_status_code(status_code), (
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
AssertionError: Status code 204 must not have a response body
adding a print statement just before this assertion shows,
print(self, self.response_model)
APIRoute(path='/test', name='test', methods=['GET']) <class 'NoneType'>
Expected
APIRoute(path='/test', name='test', methods=['GET']) None
Concerned Code:
|
new_signature = original_signature.replace( |
|
parameters=tuple(all_params.values()), |
|
return_annotation=hints.get("return", original_signature.return_annotation), |
|
) |
Possible Fix
new_signature = original_signature.replace(
parameters=tuple(all_params.values()),
return_annotation=original_signature.return_annotation,
)
Workaround
@depends
def with_test():
pass
@router.get("/test", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
@with_test
async def test() -> None:
pass
or
@depends
def with_test():
pass
@router.get("/test", status_code=status.HTTP_204_NO_CONTENT)
@with_test
async def test(): # removed return typing
pass
MRE
Error:
adding a print statement just before this assertion shows,
Expected
Concerned Code:
fastapi-decorators/fastapi_decorators/decorators.py
Lines 83 to 86 in fc37cb7
Possible Fix
Workaround
or