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

DjangoPermissionExtension does not support Channels requests. #330

Closed
nrbnlulu opened this issue Aug 7, 2023 · 6 comments · May be fixed by #331
Closed

DjangoPermissionExtension does not support Channels requests. #330

nrbnlulu opened this issue Aug 7, 2023 · 6 comments · May be fixed by #331
Labels
bug Something isn't working

Comments

@nrbnlulu
Copy link
Member

nrbnlulu commented Aug 7, 2023

On Channels requests the context is a dict so you'll get an AttributeError.
https://github.com/strawberry-graphql/strawberry-graphql-django/blob/3a3a66e236acbc54ad7079ecfa2b92508f3ad60c/strawberry_django/permissions.py#L330

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@nrbnlulu nrbnlulu added the bug Something isn't working label Aug 7, 2023
@bellini666
Copy link
Member

That's actually a general strawberry issue. Subscriptions doesn't support field extensions currently :(

@nrbnlulu
Copy link
Member Author

nrbnlulu commented Aug 7, 2023

Just ran some tests, I think it is supported with raw strawberry. Based on what do you say that?

i.e

class FooExt(FieldExtension):
    async def resolve_async(
        self, next_: AsyncExtensionResolver, source: Any, info: Info, **kwargs: Any
    ) -> Any:
        async for res in next_(source, info, **kwargs):
            yield res + 20

@strawberry.type
class Subscription:
    @strawberry.subscription(extensions=[FooExt()])
    async def subscribe_requires_auth(self) -> AsyncGenerator[int, None]:
        for i in range(5):
            yield i
            await asyncio.sleep(0.01)

@bellini666
Copy link
Member

Hrm, I remember it not being supported, but maybe that changed? =P

Will take a look at the PR you opened

@nrbnlulu
Copy link
Member Author

nrbnlulu commented Aug 7, 2023

I think you are right resolve_async must return a coroutine and for subscriptions you need to return an async generator.
I'll need to dig dipper to tell.

@bellini666
Copy link
Member

I think you are right resolve_async must return a coroutine and for subscriptions you need to return an async generator. I'll need to dig dipper to tell.

The extension can probably check the "before" permissions (i.e. the global and root permissions), but the "after" ones (i.e. retval) are more complicated because there isn't a single return value for those.

@bellini666
Copy link
Member

This should be fixed in https://github.com/strawberry-graphql/strawberry/releases/tag/0.240.0

Please let me know if that's not the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants