Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Request' object does not support item assignment #36

Open
SakuraSound opened this issue Sep 22, 2020 · 3 comments
Open

'Request' object does not support item assignment #36

SakuraSound opened this issue Sep 22, 2020 · 3 comments

Comments

@SakuraSound
Copy link

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
@koug44
Copy link

koug44 commented Oct 16, 2020

Same here w/ Sanic 20.9.0

@ashshakya
Copy link

@SakuraSound Any luck? how you resolved this error ?

@mrkiril
Copy link

mrkiril commented Oct 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants