sanic-prometheus
sanic-prometheus copied to clipboard
'Request' object does not support item assignment
Sanic no longer allows for item assignment in the request object.
I am using sanic==20.6.3 and sanic-prometheus==0.2.0
ERROR:sanic.root:Exception occurred while handling uri: 'http://localhost:8080/status/ok'
Traceback (most recent call last):
File "/home/test/.local/lib/python3.8/site-packages/sanic/app.py", line 906, in handle_request
response = await self._run_request_middleware(
File "/home/test/.local/lib/python3.8/site-packages/sanic/app.py", line 1265, in _run_request_middleware
response = await response
File "/home/test/.local/lib/python3.8/site-packages/sanic_prometheus/__init__.py", line 120, in before_request
metrics.before_request_handler(request)
File "/home/test/.local/lib/python3.8/site-packages/sanic_prometheus/metrics.py", line 52, in before_request_handler
request['__START_TIME__'] = time.time()
TypeError: 'Request' object does not support item assignment
Traceback (most recent call last):
File "/home/test/.local/lib/python3.8/site-packages/sanic/app.py", line 906, in handle_request
response = await self._run_request_middleware(
File "/home/test/.local/lib/python3.8/site-packages/sanic/app.py", line 1265, in _run_request_middleware
response = await response
File "/home/test/.local/lib/python3.8/site-packages/sanic_prometheus/__init__.py", line 120, in before_request
metrics.before_request_handler(request)
File "/home/test/.local/lib/python3.8/site-packages/sanic_prometheus/metrics.py", line 52, in before_request_handler
request['__START_TIME__'] = time.time()
TypeError: 'Request' object does not support item assignment
Same here w/ Sanic 20.9.0
@SakuraSound Any luck? how you resolved this error ?
Sanic app
and request
have slots so normally you can't add extra param there.
But all of this objects have ctx
param (context).
And you can add all you want there.
For example current user object or smth else.
request.ctx.user = user
Of course you need to refactor your code to use it, but it's ok I think