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

register fails on channles requests. #137

Closed
nrbnlulu opened this issue Oct 6, 2022 · 1 comment · Fixed by #519
Closed

register fails on channles requests. #137

nrbnlulu opened this issue Oct 6, 2022 · 1 comment · Fixed by #519

Comments

@nrbnlulu
Copy link
Owner

nrbnlulu commented Oct 6, 2022

stacktrace:

GraphQL request:2:3
1 | mutation {
2 |   register(
  |   ^
3 |     input: {email: "princebrenda@example.org", username: "stevenbrown", password1: "xW1S9aTlH@", password2: "xW1S9aTlH@"}
Traceback (most recent call last):
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/graphql/execution/execute.py", line 528, in await_result
    return_type, field_nodes, info, path, await result
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/asgiref/sync.py", line 435, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
    return await fut
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/asgiref/sync.py", line 476, in thread_handler
    return func(*args, **kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/core/field_.py", line 27, in _resolve
    return super().get_result(source, info, args, kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry_django/fields/field.py", line 112, in get_result
    return super().get_result(source, info, args, kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/field.py", line 167, in get_result
    return self.base_resolver(*args, **kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/types/fields/resolver.py", line 187, in __call__
    return self.wrapped_func(*args, **kwargs)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/core/mixins.py", line 36, in field
    return cls.resolve_mutation(info, input)  # type: ignore
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/user/resolvers.py", line 138, in resolve_mutation
    user.status.send_activation_email(info)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/models.py", line 77, in send_activation_email
    email_context = self.get_email_context(
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/gqlauth/models.py", line 62, in get_email_context
    site = get_current_site(request)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/django/contrib/sites/shortcuts.py", line 18, in get_current_site
    return RequestSite(request)
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/django/contrib/sites/requests.py", line 11, in __init__
    self.domain = self.name = request.get_host()
AttributeError: 'GraphQLHTTPConsumer' object has no attribute 'get_host'
Stack (most recent call last):
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/channels/handlers/http_handler.py", line 163, in execute
    result = await self.schema.execute(
  File "/home/nir/Desktop/tzv5hob/Backend/.venv/lib/python3.10/site-packages/strawberry/schema/schema.py", line 216, in execute
    self.process_errors(result.errors, execution_context=execution_context)

method to fix:

def get_email_context(self, info: Info, path, action, **kwargs):

@nrbnlulu
Copy link
Owner Author

nrbnlulu commented Apr 7, 2024

@shmoon-kr

I tried to fix it:
request = info.context['request'] if isinstance(info.context, dict) else info.context.request
but it still raises an error

The error is in get_current_site()
I think the solution is to implement this function ourselves.

shmoon-kr added a commit to shmoon-kr/strawberry-django-auth that referenced this issue Apr 8, 2024
nrbnlulu added a commit that referenced this issue Apr 10, 2024
* Fix register fails on channles requests. #137

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor get_email_context function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add test code for register mutation in channels context

* Revert changes by a robot

* Refactor test code of register mutation in channels context

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor test_register

* Replace verified_channels_app_communicator with unverified_channels_app_communicator

* send activation email and added a skip for the email test on channels

* Add host header in unverified_channels_app_communicator test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: ניר <88795475+nrbnlulu@users.noreply.github.com>
@nrbnlulu nrbnlulu linked a pull request Apr 10, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant