question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'AsgiRequest' object has no attribute 'register'

See original GitHub issue

Hello,

After following the installation instructions, and using the example in the README with django==2.2.1 and django-channels-graphql-ws==0.2.0 on Python 3.7.3, when making any subscription operation:

subscription {
  mySubscription {event}
}
{
  "errors": [
    {
      "message": "'AsgiRequest' object has no attribute 'register'"
    }
  ],
  "data": null
}

Traceback:

Traceback (most recent call last):
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/graphql/execution/executor.py", line 447, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
    return fn(*args, **kwargs)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/graphene_django/debug/middleware.py", line 56, in resolve
    promise = next(root, info, **args)
  File "/***.py", line 86, in resolve
    result = next(root, info, **args)
  File "/***.py", line 37, in resolve
    return next(root, info, **args)
  File "/***.py", line 8, in resolve
    return result.get()
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/promise/promise.py", line 510, in get
    return self._target_settled_value(_raise=True)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/promise/promise.py", line 514, in _target_settled_value
    return self._target()._settled_value(_raise)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/promise/promise.py", line 224, in _settled_value
    reraise(type(raise_val), raise_val, self._traceback)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/six.py", line 693, in reraise
    raise value
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/promise/promise.py", line 487, in _resolve_from_executor
    executor(resolve, reject)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/promise/promise.py", line 754, in executor
    return resolve(f(*args, **kwargs))
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/graphql/execution/middleware.py", line 76, in make_it_promise
    return next(*args, **kwargs)
  File "/.cache/pypoetry/virtualenvs/WcnE4_vK-py3.7/lib/python3.7/site-packages/channels_graphql_ws/graphql_ws.py", line 425, in _subscribe
    register = info.context.register
AttributeError: 'AsgiRequest' object has no attribute 'register'

While I can see where the ‘register’ attribute is needed: https://github.com/datadvance/DjangoChannelsGraphqlWs/blob/master/channels_graphql_ws/graphql_ws.py#L425, I can’t see what could have caused it to be deleted from the context before going through Subscription._subscribe.

Do you have any idea what could lead to that situtation, and how to fix it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hozblokcommented, May 13, 2019

Hey @rigelk ,

AsgiRequest is used in channels.http.AsgiHandler. If a http argument is not provided in channels.routing.ProtocolTypeRouter, it will default to the Django view system’s ASGI interface, channels.http.AsgiHandler.

So AsgiHandler is done specifically to work with ordinary normal Django views by default. In our example we don’t provide http, we provide websocket argument for websocket connections:

application = channels.routing.ProtocolTypeRouter(
    {
        "websocket": channels.routing.URLRouter(
            [django.urls.path("graphql/", MyGraphqlWsConsumer)]
        )
    }
)

In this way our GraphqlWsConsumer from example does not use AsgiRequest and AsgiHandler for HTTP, because AsyncJsonWebsocketConsumer doesn’t do that. The only HTTP path (after which AsgiRequest will be created) in our example is the path to graphiql, but it is not connected to GraphqlWsConsumer:

urlpatterns = [django.urls.path("", graphiql)]

Could you show how you configure ProtocolTypeRouter and urlpatterns? What kind of requests do you send to the server via HTTP? This could help reproduce this problem.

0reactions
raulhinojosacommented, Feb 12, 2020

@Thibaut-Fatus would you mind sharing a bit how you implemented this in a react app

Read more comments on GitHub >

github_iconTop Results From Across the Web

'ASGIRequest' object has no attribute 'get' in daphne django ...
@JPG Yes, as fastapi can't run itself. It needs either uvicorn or daphne (which runs under django) to run. Now I beg you...
Read more >
'ASGIRequest' object has no attribute 'get' in daphne django ...
Coding example for the question Getting AttributeError: 'ASGIRequest' object has no attribute 'get' in daphne django-django.
Read more >
WSGIRequest' object has no attribute 'get' error after submitting
I have the following codes: models.py class Job(models.Model): datetime = models.DateTimeField(default=timezone.now) associateddevice ...
Read more >
Django 2.0 and AsgiRequest Error - Google Groups
AttributeError : 'AsgiRequest' object has no attribute 'user'. So I'm hoping someone has an insight into its root cause and, maybe, a solution....
Read more >
Tutorial: Create a real-time web game with Django Channels ...
return <li key={game.id} className="list-group-item"> ... and log in on each browser with a different user (or register a new player if you only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found