fastapi-cache
fastapi-cache copied to clipboard
It reports error with "got multiple values for argument " when I use the request object directly
My code is as follows:
@app.post('/oneline', response_model=ClassifyResult)
@cache()
async def predict(sentences: Sentences,request:Request):
texts = sentences.texts
type = sentences.type
It reports error
File "C:\Users\fang_\anaconda3\envs\hmqf_dl\lib\site-packages\fastapi_cache\decorator.py", line 52, in inner
TypeError: predict() got multiple values for argument 'sentences'
after debug the code, I found that the reson maybe these line in decorator.py
:
if request.method != "GET":
return await func(request, *args, **kwargs)
The **kwargs
has the arguments request
, so it has multiple request
after I modify the code
if request.method != "GET":
return await func(*args, **kwargs)
it runs ok, but I don't know whether it has other influence.
So was it a bug or I use it a wrong way?
IMO this is a bug. Since that decorator uses pop
in order to extract the request
from kwargs
, but the issue is that it really uses a copy of kwargs, then when calls with func(request, *args, **kwargs)
use the original kwargs with the request key
in it.
This has been addressed by #130.